Task: | Ratsun reitit |
Sender: | Sartec |
Submission time: | 2020-10-01 21:59:58 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#2 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#3 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#4 | WRONG ANSWER | 0.03 s | 1, 2, 3 | details |
#5 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#6 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#7 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#8 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#9 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#10 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#11 | WRONG ANSWER | 0.04 s | 3 | details |
#12 | WRONG ANSWER | 0.06 s | 3 | details |
#13 | WRONG ANSWER | 0.06 s | 3 | details |
Code
n2 = int(input("")) dp = [[0 for i in range(n2)] for j in range(n2)]; print(dp) startCoodinateX=0 startCoodinateY=0 def getsteps(x, y, tx, ty): # if knight is on the target # position return 0. if (x == tx and y == ty): return dp[0][0]; # if already calculated then return # that value. Taking absolute difference. elif(dp[abs(x - tx)][abs(y - ty)] != 0): return dp[abs(x - tx)][abs(y - ty)]; else: # there will be two distinct positions # from the knight towards a target. # if the target is in same row or column # as of knight than there can be four # positions towards the target but in that # two would be the same and the other two # would be the same. x1, y1, x2, y2 = 0, 0, 0, 0; # (x1, y1) and (x2, y2) are two positions. # these can be different according to situation. # From position of knight, the chess board can be # divided into four blocks i.e.. N-E, E-S, S-W, W-N . if (x <= tx): if (y <= ty): x1 = x + 2; y1 = y + 1; x2 = x + 1; y2 = y + 2; else: x1 = x + 2; y1 = y - 1; x2 = x + 1; y2 = y - 2; elif (y <= ty): x1 = x - 2; y1 = y + 1; x2 = x - 1; y2 = y + 2; else: x1 = x - 2; y1 = y - 1; x2 = x - 1; y2 = y - 2; # ans will be, 1 + minimum of steps # required from (x1, y1) and (x2, y2). dp[abs(x - tx)][abs(y - ty)] = \ min(getsteps(x1, y1, tx, ty), getsteps(x2, y2, tx, ty)) + 1; # exchanging the coordinates x with y of both # knight and target will result in same ans. dp[abs(y - ty)][abs(x - tx)] = \ dp[abs(x - tx)][abs(y - ty)]; return dp[abs(x - tx)][abs(y - ty)]; # Driver Code def stepsToPoint(targetX, targetY): # size of chess board n*n n = n2*n2; # (x, y) coordinate of the knight. # (tx, ty) coordinate of the target position. x = 1; y = n2; tx = targetX; ty = targetY; # (Exception) these are the four corner points # for which the minimum steps is 4. if ((x == 1 and y == 1 and tx == 2 and ty == 2) or (x == 2 and y == 2 and tx == 1 and ty == 1)): ans = 4; elif ((x == 1 and y == n and tx == 2 and ty == n - 1) or (x == 2 and y == n - 1 and tx == 1 and ty == n)): ans = 4; elif ((x == n and y == 1 and tx == n - 1 and ty == 2) or (x == n - 1 and y == 2 and tx == n and ty == 1)): ans = 4; elif ((x == n and y == n and tx == n - 1 and ty == n - 1) or (x == n - 1 and y == n - 1 and tx == n and ty == n)): ans = 4; else: # dp[a][b], here a, b is the difference of # x & tx and y & ty respectively. dp[1][0] = 3; dp[0][1] = 3; dp[1][1] = 2; dp[2][0] = 2; dp[0][2] = 2; dp[2][1] = 1; dp[1][2] = 1; ans = getsteps(x, y, tx, ty); return ans for (y, row) in enumerate(dp): for (x, value) in enumerate(row): dp[y][x] = (stepsToPoint(x+1,n2-y)) for (i,row) in enumerate(dp): for (x, number) in enumerate(row): if x==n2-1: print(number, end="\n") else: print(number, end=" ")
Test details
Test 1
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
4 |
correct output |
---|
0 3 2 5 3 4 1 2 2 1 4 3 5 2 3 2 |
user output |
---|
[[0, 0, 0, 0], [0, 0, 0, 0], [... |
Test 2
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
5 |
correct output |
---|
0 3 2 3 2 3 4 1 2 3 2 1 4 3 2 3 2 3 2 3 2 3 2 3 4 |
user output |
---|
[[0, 0, 0, 0, 0], [0, 0, 0, 0,... Truncated |
Test 3
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
6 |
correct output |
---|
0 3 2 3 2 3 3 4 1 2 3 4 2 1 4 3 2 3 3 2 3 2 3 4 2 3 2 3 4 3 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0], [0, 0, 0,... Truncated |
Test 4
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
7 |
correct output |
---|
0 3 2 3 2 3 4 3 4 1 2 3 4 3 2 1 4 3 2 3 4 3 2 3 2 3 4 3 2 3 2 3 4 3 4 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0], [0, 0,... Truncated |
Test 5
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
8 |
correct output |
---|
0 3 2 3 2 3 4 5 3 4 1 2 3 4 3 4 2 1 4 3 2 3 4 5 3 2 3 2 3 4 3 4 2 3 2 3 4 3 4 5 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0], [0,... Truncated |
Test 6
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
9 |
correct output |
---|
0 3 2 3 2 3 4 5 4 3 4 1 2 3 4 3 4 5 2 1 4 3 2 3 4 5 4 3 2 3 2 3 4 3 4 5 2 3 2 3 4 3 4 5 4 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0], ... Truncated |
Test 7
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
10 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 3 4 1 2 3 4 3 4 5 6 2 1 4 3 2 3 4 5 4 5 3 2 3 2 3 4 3 4 5 6 2 3 2 3 4 3 4 5 4 5 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 8
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
25 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 9
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
49 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 10
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
50 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 11
Group: 3
Verdict: WRONG ANSWER
input |
---|
75 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 12
Group: 3
Verdict: WRONG ANSWER
input |
---|
99 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |
Test 13
Group: 3
Verdict: WRONG ANSWER
input |
---|
100 |
correct output |
---|
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ... |
user output |
---|
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... Truncated |