QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764880 | #3308. Remote Control | reverSilly | TL | 1ms | 10012kb | C++23 | 1.9kb | 2024-11-20 11:01:55 | 2024-11-20 11:02:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int mxn{300005},mxb{70};
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;
}
};
struct minipoint{
int8_t x,y;
minipoint(Point p):
x{p.x},y{p.y}{}
minipoint()=default;
operator Point()const
{
return {x,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;
}
minipoint &trans(int i,Point p)
{
static array<array<minipoint,mxb*2>,mxb*2>m_trans[mxn/mxb+5];
return m_trans[i][p.x+mxb][p.y+mxb];
}
Point dt[mxn];
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin>>N
>>S;
blen=round(pow(N,0.33333333333));
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
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5960kb
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: 1ms
memory: 5916kb
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: 10012kb
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...