Task: | Chess board tour |
Sender: | Nallue |
Submission time: | 2024-11-04 17:25:00 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | TIME LIMIT EXCEEDED | -- | details |
#18 | TIME LIMIT EXCEEDED | -- | details |
#19 | ACCEPTED | 0.02 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | TIME LIMIT EXCEEDED | -- | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | TIME LIMIT EXCEEDED | -- | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.02 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | TIME LIMIT EXCEEDED | -- | details |
#28 | TIME LIMIT EXCEEDED | -- | details |
#29 | TIME LIMIT EXCEEDED | -- | details |
#30 | TIME LIMIT EXCEEDED | -- | details |
#31 | TIME LIMIT EXCEEDED | -- | details |
#32 | TIME LIMIT EXCEEDED | -- | details |
#33 | TIME LIMIT EXCEEDED | -- | details |
#34 | TIME LIMIT EXCEEDED | -- | details |
#35 | TIME LIMIT EXCEEDED | -- | details |
#36 | TIME LIMIT EXCEEDED | -- | details |
#37 | TIME LIMIT EXCEEDED | -- | details |
#38 | TIME LIMIT EXCEEDED | -- | details |
#39 | TIME LIMIT EXCEEDED | -- | details |
#40 | TIME LIMIT EXCEEDED | -- | details |
#41 | RUNTIME ERROR | 0.40 s | details |
#42 | TIME LIMIT EXCEEDED | -- | details |
#43 | RUNTIME ERROR | 0.39 s | details |
#44 | TIME LIMIT EXCEEDED | -- | details |
#45 | TIME LIMIT EXCEEDED | -- | details |
#46 | TIME LIMIT EXCEEDED | -- | details |
#47 | RUNTIME ERROR | 0.40 s | details |
#48 | RUNTIME ERROR | 0.40 s | details |
#49 | RUNTIME ERROR | 0.39 s | details |
#50 | RUNTIME ERROR | 0.38 s | details |
#51 | RUNTIME ERROR | 0.40 s | details |
#52 | TIME LIMIT EXCEEDED | -- | details |
#53 | RUNTIME ERROR | 0.40 s | details |
#54 | TIME LIMIT EXCEEDED | -- | details |
#55 | TIME LIMIT EXCEEDED | -- | details |
#56 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'bool isSafe(int, std::vector<std::vector<bool> >, int*, int)': input/code.cpp:9:9: warning: unused variable 'V' [-Wunused-variable] 9 | int V = graph.size(); | ^
Code
#include <iostream> #include <bits/stdc++.h> using namespace std; bool isSafe(int v, vector<vector<bool>> graph, int path[], int pos) { int V = graph.size(); if (graph [path[pos - 1]][ v ] == 0) return false; for (int i = 0; i < pos; i++) if (path[i] == v) return false; return true; } bool hamCycleUtil(vector<vector<bool>> graph, int path[], int pos) { int V = graph.size(); if (pos == V) { if (graph[path[pos - 1]][path[0]] == 1) return true; else return false; } for (int v = 1; v < V; v++) { if (isSafe(v, graph, path, pos)) { path[pos] = v; if (hamCycleUtil (graph, path, pos + 1) == true) return true; path[pos] = -1; } } return false; } void printSolution(int path[], int V, int n, int m) { int from_x=0; int from_y=0; for (int i = 1; i < V; i++){ int y = path[i] / m; int x = path[i] % m; if(y>from_y)cout<<"D"; else if(y<from_y)cout<<"U"; else if(x>from_x)cout<<"R"; else if(x<from_x)cout<<"L"; from_x = x; from_y = y; } //cout << " /" << from_x << " , " << from_y << "/ "; if(from_y<0)cout<<"D"; else if(from_y>0)cout<<"U"; else if(from_x<0)cout<<"R"; else if(from_x>0)cout<<"L"; cout << endl; } bool hamCycle(vector<vector<bool>> graph, int n, int m) { int V = graph.size(); int *path = new int[V]; for (int i = 0; i < V; i++) path[i] = -1; path[0] = 0; if (hamCycleUtil(graph, path, 1) == false ) { cout << -1 << endl; return false; } printSolution(path, V, n, m); return true; } int main() { int m,n; cin >> n >> m; vector<vector<bool>> adj(n*m, vector<bool>(n*m,0)); for(int i=0; i<n; i++){ for(int l=0; l<m; l++){ if(i-1>=0){ adj[i*m + l][(i-1)*m +l] = 1; } if(i+1<n){ adj[i*m + l][(i+1)*m +l] = 1; } if(l-1>=0){ adj[i*m + l][i*m +l-1] = 1; } if(l+1<m){ adj[i*m + l][i*m +l+1] = 1; } } } hamCycle(adj, n, m); return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 2 |
correct output |
---|
DRUL |
user output |
---|
RDLU |
Test 2
Verdict: ACCEPTED
input |
---|
2 2 |
correct output |
---|
DRUL |
user output |
---|
RDLU |
Test 3
Verdict: ACCEPTED
input |
---|
2 3 |
correct output |
---|
RRDLLU |
user output |
---|
RRDLLU |
Test 4
Verdict: ACCEPTED
input |
---|
2 2 |
correct output |
---|
DRUL |
user output |
---|
RDLU |
Test 5
Verdict: ACCEPTED
input |
---|
4 4 |
correct output |
---|
DDDRUURDDRUUULLL |
user output |
---|
RRRDLLDRRDLLLUUU |
Test 6
Verdict: ACCEPTED
input |
---|
3 3 |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 7
Verdict: ACCEPTED
input |
---|
4 4 |
correct output |
---|
DDDRUURDDRUUULLL |
user output |
---|
RRRDLLDRRDLLLUUU |
Test 8
Verdict: ACCEPTED
input |
---|
3 5 |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 9
Verdict: ACCEPTED
input |
---|
3 2 |
correct output |
---|
DDRUUL |
user output |
---|
RDDLUU |
Test 10
Verdict: ACCEPTED
input |
---|
4 2 |
correct output |
---|
DDDRUUUL |
user output |
---|
RDDDLUUU |
Test 11
Verdict: TIME LIMIT EXCEEDED
input |
---|
5 5 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 12
Verdict: ACCEPTED
input |
---|
2 2 |
correct output |
---|
DRUL |
user output |
---|
RDLU |
Test 13
Verdict: TIME LIMIT EXCEEDED
input |
---|
5 5 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 14
Verdict: ACCEPTED
input |
---|
2 2 |
correct output |
---|
DRUL |
user output |
---|
RDLU |
Test 15
Verdict: ACCEPTED
input |
---|
5 2 |
correct output |
---|
DDDDRUUUUL |
user output |
---|
RDDDDLUUUU |
Test 16
Verdict: ACCEPTED
input |
---|
2 3 |
correct output |
---|
RRDLLU |
user output |
---|
RRDLLU |
Test 17
Verdict: TIME LIMIT EXCEEDED
input |
---|
6 7 |
correct output |
---|
RRRRRRDLLLLLDRRRRRDLLLLLDRRRRR... |
user output |
---|
(empty) |
Test 18
Verdict: TIME LIMIT EXCEEDED
input |
---|
5 10 |
correct output |
---|
DDDDRUUURDDDRUUURDDDRUUURDDDRU... |
user output |
---|
(empty) |
Test 19
Verdict: ACCEPTED
input |
---|
5 3 |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 20
Verdict: ACCEPTED
input |
---|
6 2 |
correct output |
---|
DDDDDRUUUUUL |
user output |
---|
RDDDDDLUUUUU |
Test 21
Verdict: TIME LIMIT EXCEEDED
input |
---|
10 10 |
correct output |
---|
DDDDDDDDDRUUUUUUUURDDDDDDDDRUU... |
user output |
---|
(empty) |
Test 22
Verdict: ACCEPTED
input |
---|
3 2 |
correct output |
---|
DDRUUL |
user output |
---|
RDDLUU |
Test 23
Verdict: TIME LIMIT EXCEEDED
input |
---|
10 10 |
correct output |
---|
DDDDDDDDDRUUUUUUUURDDDDDDDDRUU... |
user output |
---|
(empty) |
Test 24
Verdict: ACCEPTED
input |
---|
2 4 |
correct output |
---|
DRRRULLL |
user output |
---|
RRRDLLLU |
Test 25
Verdict: ACCEPTED
input |
---|
9 2 |
correct output |
---|
DDDDDDDDRUUUUUUUUL |
user output |
---|
RDDDDDDDDLUUUUUUUU |
Test 26
Verdict: ACCEPTED
input |
---|
2 5 |
correct output |
---|
RRRRDLLLLU |
user output |
---|
RRRRDLLLLU |
Test 27
Verdict: TIME LIMIT EXCEEDED
input |
---|
56 60 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 28
Verdict: TIME LIMIT EXCEEDED
input |
---|
43 100 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 29
Verdict: TIME LIMIT EXCEEDED
input |
---|
45 20 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 30
Verdict: TIME LIMIT EXCEEDED
input |
---|
56 9 |
correct output |
---|
RRRRRRRRDLLLLLLLDRRRRRRRDLLLLL... |
user output |
---|
(empty) |
Test 31
Verdict: TIME LIMIT EXCEEDED
input |
---|
97 91 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 32
Verdict: TIME LIMIT EXCEEDED
input |
---|
23 7 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 33
Verdict: TIME LIMIT EXCEEDED
input |
---|
90 95 |
correct output |
---|
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Test 34
Verdict: TIME LIMIT EXCEEDED
input |
---|
9 24 |
correct output |
---|
DDDDDDDDRUUUUUUURDDDDDDDRUUUUU... |
user output |
---|
(empty) |
Test 35
Verdict: TIME LIMIT EXCEEDED
input |
---|
88 3 |
correct output |
---|
RRDLDRDLDRDLDRDLDRDLDRDLDRDLDR... |
user output |
---|
(empty) |
Test 36
Verdict: TIME LIMIT EXCEEDED
input |
---|
3 38 |
correct output |
---|
DDRURDRURDRURDRURDRURDRURDRURD... |
user output |
---|
(empty) |
Test 37
Verdict: TIME LIMIT EXCEEDED
input |
---|
111 119 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 38
Verdict: TIME LIMIT EXCEEDED
input |
---|
84 200 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 39
Verdict: TIME LIMIT EXCEEDED
input |
---|
88 38 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 40
Verdict: TIME LIMIT EXCEEDED
input |
---|
111 16 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 41
Verdict: RUNTIME ERROR
input |
---|
194 181 |
correct output |
---|
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Test 42
Verdict: TIME LIMIT EXCEEDED
input |
---|
46 12 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 43
Verdict: RUNTIME ERROR
input |
---|
179 190 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 44
Verdict: TIME LIMIT EXCEEDED
input |
---|
17 47 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 45
Verdict: TIME LIMIT EXCEEDED
input |
---|
175 4 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 46
Verdict: TIME LIMIT EXCEEDED
input |
---|
4 74 |
correct output |
---|
DDDRUURDDRUURDDRUURDDRUURDDRUU... |
user output |
---|
(empty) |
Test 47
Verdict: RUNTIME ERROR
input |
---|
550 594 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 48
Verdict: RUNTIME ERROR
input |
---|
418 998 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 49
Verdict: RUNTIME ERROR
input |
---|
437 186 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 50
Verdict: RUNTIME ERROR
input |
---|
552 72 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 51
Verdict: RUNTIME ERROR
input |
---|
968 901 |
correct output |
---|
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Test 52
Verdict: TIME LIMIT EXCEEDED
input |
---|
223 57 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 53
Verdict: RUNTIME ERROR
input |
---|
893 948 |
correct output |
---|
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD... |
user output |
---|
(empty) |
Test 54
Verdict: TIME LIMIT EXCEEDED
input |
---|
78 229 |
correct output |
---|
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... |
user output |
---|
(empty) |
Test 55
Verdict: TIME LIMIT EXCEEDED
input |
---|
874 13 |
correct output |
---|
RRRRRRRRRRRRDLLLLLLLLLLLDRRRRR... |
user output |
---|
(empty) |
Test 56
Verdict: TIME LIMIT EXCEEDED
input |
---|
12 366 |
correct output |
---|
DDDDDDDDDDDRUUUUUUUUUURDDDDDDD... |
user output |
---|
(empty) |