125732024-12-23 14:45:364rt3xp02016. ápriliscpp17Accepted 32ms3240 KiB
#include<bits/stdc++.h>
using namespace std;

struct pt{
  int x,y;
};
pt operator+(const pt &l, const pt &r){
  return pt{l.x+r.x,l.y+r.y};
}
pt operator-(const pt &l, const pt &r){
  return pt{l.x-r.x,l.y-r.y};
}
bool operator<(const pt &l, const pt &r){
  return tie(l.x,l.y)<tie(r.x,r.y);
}
bool operator==(const pt &l, const pt &r){
  return tie(l.x,l.y)==tie(r.x,r.y);
}
pt rotl(pt p){
  return pt{-p.y,p.x}; 
}
pt rotr(pt p){
  return pt{p.y,-p.x};
}
pt rot(pt p){
  return pt{-p.x,-p.y};
}

int main(){
  vector<pt> d{{0,1},{1,0},{0,-1},{-1,0}}; int i=0;
  string s; cin >> s; int n=s.size();
  vector<pt> v; v.reserve(n+1); pt sum{0,0}; v.push_back(sum);
  for(char c: s){
    switch(c){
      case 'F':
        sum=sum+d[i];
        break;
      case 'R':
        i++; if(i>3) i=0;
        break;
      case 'L':
        i--; if(i<0) i=3;
        break;
    }
    v.push_back(sum);
  }
  i=0; set<pt> positions;
  for(int j=0;j<n;j++){
    switch(s[j]){
      case 'F':
        positions.insert(v[j]+rotl(v[n]-v[j+1]));
        positions.insert(v[j]+rotr(v[n]-v[j+1]));
        break;
      case 'R':
        positions.insert(v[j]+rot(v[n]-v[j+1]));
        positions.insert(v[j]+d[i]+rotl(v[n]-v[j+1]));
        i++; if(i>3) i=0;
        break;
      case 'L':
        positions.insert(v[j]+rot(v[n]-v[j+1]));
        positions.insert(v[j]+d[i]+rotr(v[n]-v[j+1]));
        i--; if(i<0) i=3;
        break;
    }
  }
  cout << positions.size() << '\n';
  /*for(pt i: positions){*/
  /*  cout << i.x << ' ' << i.y << '\n';*/
  /*}*/
}
1 - Accepted
Memory: 508KiB
Time: 1ms

Program's output:
3
Expected output:
3
Checker output:
ok 1 number(s): "3"

2 - Accepted
Memory: 2908KiB
Time: 32ms

Program's output:
34389
Expected output:
34389
Checker output:
ok 1 number(s): "34389"

3 - Accepted
Memory: 756KiB
Time: 3ms

Program's output:
3355
Expected output:
3355
Checker output:
ok 1 number(s): "3355"

4 - Accepted
Memory: 3240KiB
Time: 32ms

Program's output:
41690
Expected output:
41690
Checker output:
ok 1 number(s): "41690"

5 - Accepted
Memory: 2360KiB
Time: 26ms

Program's output:
30736
Expected output:
30736
Checker output:
ok 1 number(s): "30736"

6 - Accepted
Memory: 2872KiB
Time: 30ms

Program's output:
33948
Expected output:
33948
Checker output:
ok 1 number(s): "33948"

7 - Accepted
Memory: 2616KiB
Time: 28ms

Program's output:
34519
Expected output:
34519
Checker output:
ok 1 number(s): "34519"

8 - Accepted
Memory: 2104KiB
Time: 18ms

Program's output:
26668
Expected output:
26668
Checker output:
ok 1 number(s): "26668"

9 - Accepted
Memory: 1772KiB
Time: 14ms

Program's output:
19065
Expected output:
19065
Checker output:
ok 1 number(s): "19065"

10 - Accepted
Memory: 1848KiB
Time: 18ms

Program's output:
24051
Expected output:
24051
Checker output:
ok 1 number(s): "24051"

11 - Accepted
Memory: 1348KiB
Time: 13ms

Program's output:
15004
Expected output:
15004
Checker output:
ok 1 number(s): "15004"

12 - Accepted
Memory: 2648KiB
Time: 28ms

Program's output:
33443
Expected output:
33443
Checker output:
ok 1 number(s): "33443"

13 - Accepted
Memory: 1524KiB
Time: 10ms

Program's output:
14721
Expected output:
14721
Checker output:
ok 1 number(s): "14721"

14 - Accepted
Memory: 1736KiB
Time: 17ms

Program's output:
23380
Expected output:
23380
Checker output:
ok 1 number(s): "23380"

15 - Accepted
Memory: 1308KiB
Time: 10ms

Program's output:
15615
Expected output:
15615
Checker output:
ok 1 number(s): "15615"

16 - Accepted
Memory: 1592KiB
Time: 16ms

Program's output:
20447
Expected output:
20447
Checker output:
ok 1 number(s): "20447"

17 - Accepted
Memory: 2360KiB
Time: 25ms

Program's output:
29690
Expected output:
29690
Checker output:
ok 1 number(s): "29690"

18 - Accepted
Memory: 2292KiB
Time: 18ms

Program's output:
25230
Expected output:
25230
Checker output:
ok 1 number(s): "25230"

19 - Accepted
Memory: 1336KiB
Time: 13ms

Program's output:
16860
Expected output:
16860
Checker output:
ok 1 number(s): "16860"

20 - Accepted
Memory: 824KiB
Time: 7ms

Program's output:
9160
Expected output:
9160
Checker output:
ok 1 number(s): "9160"

21 - Accepted
Memory: 1336KiB
Time: 13ms

Program's output:
17329
Expected output:
17329
Checker output:
ok 1 number(s): "17329"

22 - Accepted
Memory: 1268KiB
Time: 9ms

Program's output:
13575
Expected output:
13575
Checker output:
ok 1 number(s): "13575"

23 - Accepted
Memory: 568KiB
Time: 4ms

Program's output:
5038
Expected output:
5038
Checker output:
ok 1 number(s): "5038"

24 - Accepted
Memory: 1080KiB
Time: 8ms

Program's output:
13363
Expected output:
13363
Checker output:
ok 1 number(s): "13363"

25 - Accepted
Memory: 2476KiB
Time: 27ms

Program's output:
29598
Expected output:
29598
Checker output:
ok 1 number(s): "29598"

26 - Accepted
Memory: 2948KiB
Time: 32ms

Program's output:
38908
Expected output:
38908
Checker output:
ok 1 number(s): "38908"