QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641472 | #50. Knight | test123 | 100 ✓ | 0ms | 3940kb | C++14 | 1.1kb | 2024-10-14 20:40:14 | 2024-10-14 20:40:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=10;
const int a[8][2]={{1,2},{1,-2},{2,1},{2,-1},{-1,2},{-1,-2},{-2,-1},{-2,1}};
int read(){
int ret=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
return ret*f;
}
char ch;
int n=8,p1,p2;
int step[maxn][maxn];
struct node{
int x,y;
}que[maxn*maxn];
bool check(int x,int y){
return 1<=x&&x<=8&&1<=y&&y<=8&&!step[x][y];
}
void BFS(){
int hed=1,til=1;
step[p1][p2]=1;
que[++til]=(node){p1,p2};
while(hed<til){
node now=que[++hed];
for(int i=0;i<8;++i){
int x_=now.x+a[i][0],y_=now.y+a[i][1];
if(check(x_,y_)){
step[x_][y_]=step[now.x][now.y]+1;
que[++til]=(node){x_,y_};
}
}
}
}
int main(){
ch=getchar();
while(!islower(ch)) ch=getchar();
p1=ch-'a'+1;
ch=getchar();
while(!isdigit(ch)) ch=getchar();
p2=ch-'0';
BFS();
ch=getchar();
while(!islower(ch)) ch=getchar();
p1=ch-'a'+1;
ch=getchar();
while(!isdigit(ch)) ch=getchar();
p2=ch-'0';
printf("%d\n",step[p1][p2]-1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 1
Accepted
time: 0ms
memory: 3808kb
input:
b4 b2
output:
2
result:
ok single line: '2'
Test #2:
score: 1
Accepted
time: 0ms
memory: 3792kb
input:
h1 h2
output:
3
result:
ok single line: '3'
Test #3:
score: 1
Accepted
time: 0ms
memory: 3824kb
input:
h1 a8
output:
6
result:
ok single line: '6'
Test #4:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
b2 f7
output:
3
result:
ok single line: '3'
Test #5:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
d5 d3
output:
2
result:
ok single line: '2'
Test #6:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
h2 a4
output:
5
result:
ok single line: '5'
Test #7:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
e8 b4
output:
3
result:
ok single line: '3'
Test #8:
score: 1
Accepted
time: 0ms
memory: 3832kb
input:
f3 c2
output:
2
result:
ok single line: '2'
Test #9:
score: 1
Accepted
time: 0ms
memory: 3744kb
input:
f4 a6
output:
3
result:
ok single line: '3'
Test #10:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
f6 g6
output:
3
result:
ok single line: '3'
Test #11:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
h4 h5
output:
3
result:
ok single line: '3'
Test #12:
score: 1
Accepted
time: 0ms
memory: 3940kb
input:
d2 g7
output:
4
result:
ok single line: '4'
Test #13:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
c1 e7
output:
4
result:
ok single line: '4'
Test #14:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
a4 h5
output:
4
result:
ok single line: '4'
Test #15:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
f2 a6
output:
3
result:
ok single line: '3'
Test #16:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
e8 d1
output:
4
result:
ok single line: '4'
Test #17:
score: 1
Accepted
time: 0ms
memory: 3824kb
input:
g3 b3
output:
3
result:
ok single line: '3'
Test #18:
score: 1
Accepted
time: 0ms
memory: 3940kb
input:
f7 h2
output:
3
result:
ok single line: '3'
Test #19:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
b8 h3
output:
5
result:
ok single line: '5'
Test #20:
score: 1
Accepted
time: 0ms
memory: 3800kb
input:
g4 a4
output:
4
result:
ok single line: '4'
Test #21:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
h7 h7
output:
0
result:
ok single line: '0'
Test #22:
score: 1
Accepted
time: 0ms
memory: 3824kb
input:
b2 b4
output:
2
result:
ok single line: '2'
Test #23:
score: 1
Accepted
time: 0ms
memory: 3940kb
input:
g2 b5
output:
4
result:
ok single line: '4'
Test #24:
score: 1
Accepted
time: 0ms
memory: 3772kb
input:
g2 g8
output:
4
result:
ok single line: '4'
Test #25:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
e1 a2
output:
3
result:
ok single line: '3'
Test #26:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
b2 e8
output:
3
result:
ok single line: '3'
Test #27:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
e2 c4
output:
4
result:
ok single line: '4'
Test #28:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
g1 d3
output:
3
result:
ok single line: '3'
Test #29:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
g4 d1
output:
2
result:
ok single line: '2'
Test #30:
score: 1
Accepted
time: 0ms
memory: 3880kb
input:
g1 e5
output:
2
result:
ok single line: '2'
Test #31:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
h4 f4
output:
2
result:
ok single line: '2'
Test #32:
score: 1
Accepted
time: 0ms
memory: 3736kb
input:
c2 d8
output:
3
result:
ok single line: '3'
Test #33:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
c1 g7
output:
4
result:
ok single line: '4'
Test #34:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
g8 b1
output:
4
result:
ok single line: '4'
Test #35:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
a7 c5
output:
4
result:
ok single line: '4'
Test #36:
score: 1
Accepted
time: 0ms
memory: 3880kb
input:
e8 h3
output:
4
result:
ok single line: '4'
Test #37:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
h8 c8
output:
3
result:
ok single line: '3'
Test #38:
score: 1
Accepted
time: 0ms
memory: 3744kb
input:
g8 c5
output:
3
result:
ok single line: '3'
Test #39:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
a7 b8
output:
2
result:
ok single line: '2'
Test #40:
score: 1
Accepted
time: 0ms
memory: 3772kb
input:
a6 g4
output:
4
result:
ok single line: '4'
Test #41:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
c8 g3
output:
3
result:
ok single line: '3'
Test #42:
score: 1
Accepted
time: 0ms
memory: 3776kb
input:
h8 e2
output:
3
result:
ok single line: '3'
Test #43:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
f4 g4
output:
3
result:
ok single line: '3'
Test #44:
score: 1
Accepted
time: 0ms
memory: 3732kb
input:
e2 a3
output:
3
result:
ok single line: '3'
Test #45:
score: 1
Accepted
time: 0ms
memory: 3744kb
input:
a3 h3
output:
5
result:
ok single line: '5'
Test #46:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
g6 h2
output:
3
result:
ok single line: '3'
Test #47:
score: 1
Accepted
time: 0ms
memory: 3728kb
input:
g3 g8
output:
3
result:
ok single line: '3'
Test #48:
score: 1
Accepted
time: 0ms
memory: 3764kb
input:
g6 c1
output:
3
result:
ok single line: '3'
Test #49:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
a8 b8
output:
3
result:
ok single line: '3'
Test #50:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
e8 c2
output:
4
result:
ok single line: '4'
Test #51:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
d4 b2
output:
4
result:
ok single line: '4'
Test #52:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
g7 b1
output:
5
result:
ok single line: '5'
Test #53:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
b2 f4
output:
2
result:
ok single line: '2'
Test #54:
score: 1
Accepted
time: 0ms
memory: 3776kb
input:
h5 a1
output:
5
result:
ok single line: '5'
Test #55:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
b1 e8
output:
4
result:
ok single line: '4'
Test #56:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
g7 h4
output:
2
result:
ok single line: '2'
Test #57:
score: 1
Accepted
time: 0ms
memory: 3792kb
input:
h4 g8
output:
3
result:
ok single line: '3'
Test #58:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
f6 f4
output:
2
result:
ok single line: '2'
Test #59:
score: 1
Accepted
time: 0ms
memory: 3796kb
input:
d2 d5
output:
3
result:
ok single line: '3'
Test #60:
score: 1
Accepted
time: 0ms
memory: 3748kb
input:
g4 b6
output:
3
result:
ok single line: '3'
Test #61:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
e1 c8
output:
5
result:
ok single line: '5'
Test #62:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
f3 d4
output:
1
result:
ok single line: '1'
Test #63:
score: 1
Accepted
time: 0ms
memory: 3808kb
input:
a7 b5
output:
1
result:
ok single line: '1'
Test #64:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
h4 g7
output:
2
result:
ok single line: '2'
Test #65:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
h3 a3
output:
5
result:
ok single line: '5'
Test #66:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
h7 d4
output:
3
result:
ok single line: '3'
Test #67:
score: 1
Accepted
time: 0ms
memory: 3780kb
input:
a3 h4
output:
4
result:
ok single line: '4'
Test #68:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
d7 e5
output:
1
result:
ok single line: '1'
Test #69:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
f4 h6
output:
4
result:
ok single line: '4'
Test #70:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
d8 c8
output:
3
result:
ok single line: '3'
Test #71:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
e1 a4
output:
3
result:
ok single line: '3'
Test #72:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
g2 a3
output:
3
result:
ok single line: '3'
Test #73:
score: 1
Accepted
time: 0ms
memory: 3940kb
input:
f6 d1
output:
3
result:
ok single line: '3'
Test #74:
score: 1
Accepted
time: 0ms
memory: 3828kb
input:
e1 h4
output:
2
result:
ok single line: '2'
Test #75:
score: 1
Accepted
time: 0ms
memory: 3936kb
input:
h7 f8
output:
1
result:
ok single line: '1'
Test #76:
score: 1
Accepted
time: 0ms
memory: 3832kb
input:
d7 c6
output:
2
result:
ok single line: '2'
Test #77:
score: 1
Accepted
time: 0ms
memory: 3936kb
input:
e5 c1
output:
2
result:
ok single line: '2'
Test #78:
score: 1
Accepted
time: 0ms
memory: 3820kb
input:
f1 d2
output:
1
result:
ok single line: '1'
Test #79:
score: 1
Accepted
time: 0ms
memory: 3884kb
input:
b3 h6
output:
3
result:
ok single line: '3'
Test #80:
score: 1
Accepted
time: 0ms
memory: 3748kb
input:
e7 g2
output:
3
result:
ok single line: '3'
Test #81:
score: 1
Accepted
time: 0ms
memory: 3816kb
input:
h3 e5
output:
3
result:
ok single line: '3'
Test #82:
score: 1
Accepted
time: 0ms
memory: 3768kb
input:
c3 h2
output:
4
result:
ok single line: '4'
Test #83:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
d4 b8
output:
2
result:
ok single line: '2'
Test #84:
score: 1
Accepted
time: 0ms
memory: 3736kb
input:
c2 e5
output:
3
result:
ok single line: '3'
Test #85:
score: 1
Accepted
time: 0ms
memory: 3824kb
input:
b8 a3
output:
4
result:
ok single line: '4'
Test #86:
score: 1
Accepted
time: 0ms
memory: 3776kb
input:
e5 h8
output:
2
result:
ok single line: '2'
Test #87:
score: 1
Accepted
time: 0ms
memory: 3796kb
input:
g5 g2
output:
3
result:
ok single line: '3'
Test #88:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
f3 a1
output:
3
result:
ok single line: '3'
Test #89:
score: 1
Accepted
time: 0ms
memory: 3756kb
input:
e7 e5
output:
2
result:
ok single line: '2'
Test #90:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
f3 c3
output:
3
result:
ok single line: '3'
Test #91:
score: 1
Accepted
time: 0ms
memory: 3792kb
input:
g5 e6
output:
1
result:
ok single line: '1'
Test #92:
score: 1
Accepted
time: 0ms
memory: 3876kb
input:
e7 e6
output:
3
result:
ok single line: '3'
Test #93:
score: 1
Accepted
time: 0ms
memory: 3872kb
input:
a4 d6
output:
3
result:
ok single line: '3'
Test #94:
score: 1
Accepted
time: 0ms
memory: 3776kb
input:
b6 h6
output:
4
result:
ok single line: '4'
Test #95:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
b7 b2
output:
3
result:
ok single line: '3'
Test #96:
score: 1
Accepted
time: 0ms
memory: 3764kb
input:
a6 f2
output:
3
result:
ok single line: '3'
Test #97:
score: 1
Accepted
time: 0ms
memory: 3812kb
input:
b2 e2
output:
3
result:
ok single line: '3'
Test #98:
score: 1
Accepted
time: 0ms
memory: 3760kb
input:
e4 d4
output:
3
result:
ok single line: '3'
Test #99:
score: 1
Accepted
time: 0ms
memory: 3752kb
input:
b8 c7
output:
2
result:
ok single line: '2'
Test #100:
score: 1
Accepted
time: 0ms
memory: 3772kb
input:
a1 h8
output:
6
result:
ok single line: '6'