QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#764813#3308. Remote ControlreverSillyTL 1ms6440kbC++231.7kb2024-11-20 10:48:212024-11-20 10:48:21

Judging History

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

  • [2024-11-20 10:48:21]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:6440kb
  • [2024-11-20 10:48:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int mxn{50000};
struct Point{
	int x,y;
	void execute(char op)
	{
		if(op=='L')
			if(pair{x,y}!=pair{1,0})
				--x;
		if(op=='R')
			if(pair{x,y}!=pair{-1,0})
				++x;
		if(op=='U')
			if(pair{x,y}!=pair{0,-1})
				++y;
		if(op=='D')
			if(pair{x,y}!=pair{0,1})
				--y;
	}
};
int abs(Point p)
{
	return abs(p.x)+abs(p.y);
}
int N,Q,blen;
int b(int i)
{
	return i/blen;
}
int bn()
{
	return (N-1)/blen+1;
}
string S;
Point execute(Point ini,int L,int R)
{
	for(int i=L;i<R;++i)
	{
		ini.execute(S[i]);
		// cerr<<S[i]<<' '<<ini.x<<' '<<ini.y<<'\n';
	}
	return ini;
}
Point &trans(int i,Point p)
{
	static array<array<Point,60>,60>m_trans[mxn];
	return m_trans[i][p.x+50][p.y+50];
}
Point dt[mxn];
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin>>N
		>>S;
	blen=round(pow(N,0.333333333));
	cerr<<"blen="<<blen<<'\n';
	for(int i=0;i<bn();++i)
	{
		Point ini;
		for(ini.x=-blen;ini.x<=blen;++ini.x)
		{
			for(ini.y=-blen;ini.y<=blen;++ini.y)
			{
				if(abs(ini)<=blen)
				{
					trans(i,ini)=execute(ini,i*blen,min(N,i*blen+blen));
					// cerr<<"trans "<<trans(i,ini).x<<' '<<trans(i,ini).y<<'\n';
				}
			}
		}
		dt[i]={100000,0};
		dt[i]=execute(dt[i],i*blen,min(N,i*blen+blen));
		dt[i].x-=100000;
	}
	cin>>Q;
	for(int i=0;i<Q;++i)
	{
		Point p;
		cin>>p.x>>p.y;
		for(int i=0;i<bn();++i)
		{
			if(abs(p)>blen)
			{
				p.x+=dt[i].x;
				p.y+=dt[i].y;
				// cerr<<"dt "<<dt[i].x<<' '<<dt[i].y<<'\n';
			}
			else
				p=trans(i,p);
			// cerr<<p.x<<' '<<p.y<<'\n';
		}
		cout<<p.x<<' '<<p.y<<'\n';
	}
	return 0;
}
// 8
// RRDRUULL
// 5
// -2 1
// -2 2
// -2 -1 
// -3 -1
// 1 1

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3892kb

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: 0
Accepted
time: 0ms
memory: 3776kb

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 3
2 3
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:

ok 18 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 6440kb

input:

1000
ULRULRURDDDLURUURULUDRDDRDLURRRUDDDDDURURUDDDRLLDURDDDLLDLULUURDRRDDDURDDRLRULDLUULDLRDLURUUUUDDRULDRRUDDDDUUULLURDUUUULDLDDUUUDUUUUDDLURLUDDDUDLDLRRUDURDRDLRURLUULDRLRDRDDRDRRDLUUURURLRLDUDLDLRURLURUDRRULDRDDRUDDDRURDRRDLDLRDLRDUDDLLLLRUULRRUDURUUUDDDLRDRDRDRURUDDURUDLRLDLLDDULURDURDLLLUULLDLD...

output:

-105 -4
17 -30
41 80
6 -100
23 28
10 -58
-22 -34
1 24
-46 -79
-43 87
-102 -76
85 25
-42 -3
-71 36
-55 -109
-39 -105
5 -102
82 15
42 -22
81 63
-64 -7
-82 -62
74 9
-41 37
21 18
-109 -38
51 48
10 -46
-37 28
-18 -110
-67 -74
-96 -55
-5 16
-49 -21
-81 -56
-106 27
62 48
21 59
-79 72
4 29
17 -65
87 44
72 1...

result:

ok 1000 lines

Test #4:

score: -100
Time Limit Exceeded

input:

300000
DDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURU...

output:


result: