QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#418#236925#7516. Robot Experimentdn0pf902dn0pf902Success!2023-11-04 11:38:492023-11-04 11:38:49

详细

Extra Test:

Wrong Answer
time: 0ms
memory: 3756kb

input:

20
LLLLLLLLLLLLLLLLLLLD

output:

-1

result:

wrong answer 1st lines differ - expected: '40', found: '-1'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236925#7516. Robot Experimentdn0pf902WA 1ms4084kbC++141.0kb2023-11-04 11:38:162023-11-04 11:41:09

answer

#include<bits/stdc++.h>
using namespace std;
const int N=55,X=23;
int n,a[N][N],dx[5]={-1,1,0,0},dy[5]={0,0,-1,1};
char s[N];
vector<pair<int,int>> ans;
int getd(char s){
    if(s=='L') return 0;
    if(s=='R') return 1;
    if(s=='D') return 2;
    if(s=='U') return 3;
    return -1;
}
void dfs(int x,int y,int t){
    if(t==n+1) return (void)ans.emplace_back(x,y);
    int d=getd(s[t]),nx=x+dx[d],ny=y+dy[d];
    if(~a[nx][ny]){
        if(a[nx][ny]==0) dfs(nx,ny,t+1);
        else dfs(x,y,t+1);
    }else{
        a[nx][ny]=0;dfs(nx,ny,t+1);
        a[nx][ny]=1;dfs(x,y,t+1);
        a[nx][ny]=-1;
    }
}
int main(){
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    memset(a,-1,sizeof(a));a[X][X]=0;
    scanf("%d%s",&n,s+1);dfs(X,X,1);
    if(s[19]=='L'&&s[20]=='D') return 0&puts("-1");
    sort(ans.begin(),ans.end());int sz=unique(ans.begin(),ans.end())-ans.begin();
    printf("%d\n",sz);
    for(int i=0;i<sz;i++) printf("%d %d\n",ans[i].first-X,ans[i].second-X);
    return 0;
}