QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#54475 | #3308. Remote Control | EastIsRed | WA | 2ms | 3824kb | C++23 | 1.3kb | 2022-10-08 21:30:50 | 2022-10-08 21:30:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,q;
int pos[300086][2];
char s[300086];
int fa[300086];
int getfa(int u)
{
if(u==fa[u])
return u;
return fa[u]=getfa(fa[u]);
}
map<pair<int,int>,int>st;
int main()
{
scanf("%d",&n);
scanf("%s",s);
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int x,y;
scanf("%d%d",&x,&y);
pos[i][0]=x,pos[i][1]=y;
st[make_pair(x,y)]=i;
fa[i]=i;
}
int n1=0,n2=0;
for(int i=0;i<n;i++)
{
int move_temp1=0,move_temp2=0;
if(s[i]=='U')
{
n2--;
move_temp2=-1;
}
else if(s[i]=='D')
{
n2++;
move_temp2=1;
}
else if(s[i]=='L')
{
n1++;
move_temp1=1;
}
else
{
n1--;
move_temp1=-1;
}
if(st.count(make_pair(n1,n2)))
{
if(st.count(make_pair(n1+move_temp1,n2+move_temp2)))
{
fa[st[make_pair(n1,n2)]]=st[make_pair(n1+move_temp1,n2+move_temp2)];
st.erase(make_pair(n1,n2));
}
else
{
int temp=st[make_pair(n1,n2)];
st.erase(make_pair(n1,n2));
st[make_pair(n1+move_temp1,n2+move_temp2)]=temp;
pos[temp][0]=n1+move_temp1,pos[temp][1]=n2+move_temp2;
}
}
}
for(int i=1;i<=q;i++)
{
int f=getfa(i);
printf("%d %d\n",pos[f][0]-n1,pos[f][1]-n2);
}
return 0;
}
/*
8
RRDRUULL
5
-2 1
-2 2
-2 -1
-3 -1
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3824kb
input:
8 RRDRUULL 5 -2 1 -2 2 -2 -1 -3 -1 1 1
output:
-1 3 -1 3 1 0 -2 -1 2 2
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3788kb
input:
8 LLDDRRUU 18 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
output:
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 1 1 -1 2 1 3 2 3 2 3 2 3 3 1 3 2 3 3
result:
wrong answer 2nd lines differ - expected: '-1 2', found: '1 2'