QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545465 | #7512. Almost Prefix Concatenation | Liangsheng298# | WA | 1ms | 3592kb | C++14 | 1.9kb | 2024-09-03 13:21:18 | 2024-09-03 13:21:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(){
T x=0;char ch=getchar();bool fl=false;
while(!isdigit(ch)){if(ch=='-')fl=true;ch=getchar();}
while(isdigit(ch)){
x=(x<<3)+(x<<1)+(ch^48);ch=getchar();
}
return fl?-x:x;
}
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define LL long long
#define read() read<int>()
int n;
char s[25];
#define Pair pair<int,int>
set<Pair> S;
map<Pair,int> mp;
void dfs(int de,int x,int y){
if(de==n+1){
S.insert(make_pair(x,y));return ;
}
if(s[de]=='L'){
auto t=make_pair(x-1,y);
if(!mp[t]){
mp[t]=1;dfs(de+1,t.first,t.second);
mp[t]=-1;dfs(de+1,x,y);
mp[t]=0;
}
else if(mp[t]==1)dfs(de+1,t.first,t.second);
else dfs(de+1,x,y);
}
else if(s[de]=='R'){
auto t=make_pair(x+1,y);
if(!mp[t]){
mp[t]=1;dfs(de+1,t.first,t.second);
mp[t]=-1;dfs(de+1,x,y);
mp[t]=0;
}
else if(mp[t]==1)dfs(de+1,t.first,t.second);
else dfs(de+1,x,y);
}
else if(s[de]=='U'){
auto t=make_pair(x,y+1);
if(!mp[t]){
mp[t]=1;dfs(de+1,t.first,t.second);
mp[t]=-1;dfs(de+1,x,y);
mp[t]=0;
}
else if(mp[t]==1)dfs(de+1,t.first,t.second);
else dfs(de+1,x,y);
}
else {
auto t=make_pair(x,y-1);
if(!mp[t]){
mp[t]=1;dfs(de+1,t.first,t.second);
mp[t]=-1;dfs(de+1,x,y);
mp[t]=0;
}
else if(mp[t]==1)dfs(de+1,t.first,t.second);
else dfs(de+1,x,y);
}
}
int main(){
FASTIO;
cin>>n>>(s+1);
mp[make_pair(0,0)]=true;
dfs(1,0,0);
cout<<S.size()<<'\n';
for(auto t:S)cout<<t.first<<' '<<t.second<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3592kb
input:
ababaab aba
output:
1 0 0
result:
wrong answer 1st numbers differ - expected: '473', found: '1'