12573 | 2024-12-23 14:45:36 | 4rt3xp0 | 2016. április | cpp17 | Accepted | 32ms | 3240 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';*/
/*}*/
}
3
Expected output:3
Checker output:ok 1 number(s): "3"
34389
Expected output:34389
Checker output:ok 1 number(s): "34389"
3355
Expected output:3355
Checker output:ok 1 number(s): "3355"
41690
Expected output:41690
Checker output:ok 1 number(s): "41690"
30736
Expected output:30736
Checker output:ok 1 number(s): "30736"
33948
Expected output:33948
Checker output:ok 1 number(s): "33948"
34519
Expected output:34519
Checker output:ok 1 number(s): "34519"
26668
Expected output:26668
Checker output:ok 1 number(s): "26668"
19065
Expected output:19065
Checker output:ok 1 number(s): "19065"
24051
Expected output:24051
Checker output:ok 1 number(s): "24051"
15004
Expected output:15004
Checker output:ok 1 number(s): "15004"
33443
Expected output:33443
Checker output:ok 1 number(s): "33443"
14721
Expected output:14721
Checker output:ok 1 number(s): "14721"
23380
Expected output:23380
Checker output:ok 1 number(s): "23380"
15615
Expected output:15615
Checker output:ok 1 number(s): "15615"
20447
Expected output:20447
Checker output:ok 1 number(s): "20447"
29690
Expected output:29690
Checker output:ok 1 number(s): "29690"
25230
Expected output:25230
Checker output:ok 1 number(s): "25230"
16860
Expected output:16860
Checker output:ok 1 number(s): "16860"
9160
Expected output:9160
Checker output:ok 1 number(s): "9160"
17329
Expected output:17329
Checker output:ok 1 number(s): "17329"
13575
Expected output:13575
Checker output:ok 1 number(s): "13575"
5038
Expected output:5038
Checker output:ok 1 number(s): "5038"
13363
Expected output:13363
Checker output:ok 1 number(s): "13363"
29598
Expected output:29598
Checker output:ok 1 number(s): "29598"
38908
Expected output:38908
Checker output:ok 1 number(s): "38908"