QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#54475#3308. Remote ControlEastIsRedWA 2ms3824kbC++231.3kb2022-10-08 21:30:502022-10-08 21:30:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-08 21:30:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3824kb
  • [2022-10-08 21:30:50]
  • 提交

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
*/

Details

Tip: Click on the bar to expand more detailed information

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'