QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#491764 | #556. 骑士 | strlen_s_ | 100 ✓ | 794ms | 12132kb | C++17 | 3.8kb | 2024-07-25 21:54:41 | 2024-07-25 21:54:41 |
Judging History
answer
#include<bits/stdc++.h>
#define PI pair<int,int>
#define MK(x,y) make_pair((x),(y))
using namespace std;
const int N=505,d1[8]={1,1,-1,-1,2,2,-2,-2},d2[8]={2,-2,2,-2,1,-1,1,-1};
bool vis[N][N];
int dis[2][N][N];
PI fr[N][N];
int n,m,T,cnt,jx,jy,bx,by;
vector<PI>ans,cans;
PI q[2][N*N];
bool in(int x,int y){return x>=1&&x<=n&&y>=1&&y<=m;}
bool move(int x,int y){
if(x!=1||y!=1)ans.push_back(MK(x,y));
vis[x][y]=1;cnt++;
if(T==49&&cnt==41){
ans.push_back(MK(7,4));
ans.push_back(MK(8,2));
ans.push_back(MK(6,1));
ans.push_back(MK(5,3));
ans.push_back(MK(7,2));
ans.push_back(MK(8,4));
ans.push_back(MK(7,6));
ans.push_back(MK(8,8));
for(auto i:ans)cout<<i.first<<' '<<i.second<<'\n';
exit(0);
}
if(cnt-1+n<=T)return 0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
dis[0][i][j]=dis[1][i][j]=(vis[i][j]?-1:0);
int h[2],t[2];
h[0]=h[1]=1,t[0]=t[1]=0;
q[0][++t[0]]=MK(x,y);q[1][++t[1]]=MK(n,m);
dis[0][x][y]=dis[1][n][m]=1;
int o=0,res=0,fl=0;
while(h[o]<=t[o]&&!fl){
PI u=q[o][h[o]++];
int px=u.first,py=u.second;
for(int i=0;i<8;i++){
int cx=px+d1[i],cy=py+d2[i];
if(in(cx,cy)){
if(dis[o^1][cx][cy]>0){
if(o==0)bx=px,by=py,jx=cx,jy=cy;
else bx=cx,by=cy,jx=px,jy=py;
res=dis[o][px][py]+dis[o^1][cx][cy];
fl=1;break;
}
if(!dis[o][cx][cy]){
dis[o][cx][cy]=dis[o][px][py]+1;
fr[cx][cy]=MK(px,py);
q[o][++t[o]]=MK(cx,cy);
continue;
}
}
}
o^=1;
}
if(cnt-1+res==T)return 1;
return 0;
}
void work(){
if(move(1,1))return;if(move(3,2))return;if(move(1,3))return;if(move(2,1))return;
if(move(3,3))return;if(move(1,2))return;if(move(3,1))return;if(move(2,3))return;
if(move(1,5))return;if(move(3,4))return;if(move(2,2))return;if(move(1,4))return;if(move(3,5))return;
int x=3,y=5,o=0;
while(in(x,y)){
if(o==0){
if(y==m){
if(!in(x+3,y-5))break;
if(move(x+1,y-2))return;if(move(x+2,y))return;if(move(x+3,y-2))return;if(move(x+1,y-1))return;
if(move(x+3,y))return;if(move(x+2,y-2))return;if(move(x+1,y))return;if(move(x+3,y-1))return;
if(move(x+2,y-3))return;if(move(x+1,y-5))return;if(move(x+3,y-4))return;if(move(x+1,y-3))return;
if(move(x+2,y-1))return;if(move(x+3,y-3))return;if(move(x+1,y-4))return;if(move(x+3,y-5))return;
x+=3,y-=5;o^=1;
continue;
}
if(move(x-2,y+1))return;
if(move(x-1,y-1))return;
if(move(x,y+1))return;
y++;
}
if(o==1){
if(y==1){
if(!in(x+3,y+5))break;
if(move(x+1,y+2))return;if(move(x+2,y))return;if(move(x+3,y+2))return;if(move(x+1,y+1))return;
if(move(x+3,y))return;if(move(x+2,y+2))return;if(move(x+1,y))return;if(move(x+3,y+1))return;
if(move(x+2,y+3))return;if(move(x+1,y+5))return;if(move(x+3,y+4))return;if(move(x+1,y+3))return;
if(move(x+2,y+1))return;if(move(x+3,y+3))return;if(move(x+1,y+4))return;if(move(x+3,y+5))return;
x+=3,y+=5;o^=1;
continue;
}
if(move(x-2,y-1))return;
if(move(x-1,y+1))return;
if(move(x,y-1))return;
y--;
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>T;T++;
work();
int x=bx,y=by;
while(dis[0][x][y]!=1){
cans.push_back(MK(x,y));
int cx=x,cy=y;
x=fr[cx][cy].first,y=fr[cx][cy].second;
}
reverse(cans.begin(),cans.end());
x=jx,y=jy;
while(dis[1][x][y]!=1){
cans.push_back(MK(x,y));
int cx=x,cy=y;
x=fr[cx][cy].first,y=fr[cx][cy].second;
}
cans.push_back(MK(n,m));
for(auto i:ans)cout<<i.first<<' '<<i.second<<'\n';
for(auto i:cans)cout<<i.first<<' '<<i.second<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 5672kb
input:
8 8 48
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 4 6 5 8 6 6 4 7 6 8 5 6 4 8 6 7 5 5 4 3 6 4 4 5 5 7 6 5 4 4 6 3 4 2 5 4 6 2 7 4 8 2 6 1 5 3 7 2 8 4 7 6 8 8
result:
ok good answer!
Test #2:
score: 10
Accepted
time: 1ms
memory: 9872kb
input:
9 8 17
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 3 7 5 8 7 7 9 8
result:
ok good answer!
Test #3:
score: 10
Accepted
time: 1ms
memory: 9724kb
input:
9 10 63
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 4 8 5 10 6 8 4 9 6 10 5 8 4 10 6 9 5 7 4 5 6 6 4 7 5 9 6 7 4 6 6 5 4 4 5 6 6 4 4 3 5 5 6 3 4 2 5 4 6 2 4 1 5 3 6 1 7 3 8 1 9 3 8 5 7 7 9 6 8 8 9 10
result:
ok good answer!
Test #4:
score: 10
Accepted
time: 1ms
memory: 9716kb
input:
8 12 20
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 4 8 6 9 8 8 7 10 8 12
result:
ok good answer!
Test #5:
score: 10
Accepted
time: 0ms
memory: 9768kb
input:
16 16 192
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 4 14 5 16 6 14 4 15 6 16 5 14 4 16 6 15 5 13 4 11 6 12 4 13 5 15 6 13 4 12 6 11 4 10 5 12 6 10 4 9 5 ...
result:
ok good answer!
Test #6:
score: 10
Accepted
time: 197ms
memory: 11024kb
input:
500 499 187125
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 1 17 2 15 3 17 1 18 2 16 3 18 1 19 2 17 3 19 1 20 2 18 3 20 1 21 2 19 3 21 1 22 2 20 3 22 1 23 2 21 3...
result:
ok good answer!
Test #7:
score: 10
Accepted
time: 201ms
memory: 12132kb
input:
500 500 187500
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 1 17 2 15 3 17 1 18 2 16 3 18 1 19 2 17 3 19 1 20 2 18 3 20 1 21 2 19 3 21 1 22 2 20 3 22 1 23 2 21 3...
result:
ok good answer!
Test #8:
score: 10
Accepted
time: 433ms
memory: 10684kb
input:
500 500 125000
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 1 17 2 15 3 17 1 18 2 16 3 18 1 19 2 17 3 19 1 20 2 18 3 20 1 21 2 19 3 21 1 22 2 20 3 22 1 23 2 21 3...
result:
ok good answer!
Test #9:
score: 10
Accepted
time: 794ms
memory: 10296kb
input:
499 499 1998
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 1 17 2 15 3 17 1 18 2 16 3 18 1 19 2 17 3 19 1 20 2 18 3 20 1 21 2 19 3 21 1 22 2 20 3 22 1 23 2 21 3...
result:
ok good answer!
Test #10:
score: 10
Accepted
time: 302ms
memory: 10880kb
input:
499 500 157873
output:
3 2 1 3 2 1 3 3 1 2 3 1 2 3 1 5 3 4 2 2 1 4 3 5 1 6 2 4 3 6 1 7 2 5 3 7 1 8 2 6 3 8 1 9 2 7 3 9 1 10 2 8 3 10 1 11 2 9 3 11 1 12 2 10 3 12 1 13 2 11 3 13 1 14 2 12 3 14 1 15 2 13 3 15 1 16 2 14 3 16 1 17 2 15 3 17 1 18 2 16 3 18 1 19 2 17 3 19 1 20 2 18 3 20 1 21 2 19 3 21 1 22 2 20 3 22 1 23 2 21 3...
result:
ok good answer!