#include <iostream>
using namespace std;
int n;
string s;
string ns[11];
bool isfound=false;
bool valid(int x, int y){
return x >= 0 && x < 10 && y >= 0 && y <= n;
}
void DFS(int x, int y, int second, bool isclicked, int startedsecond, string str, int p){
ns[x][y] = 'X';
if(isfound == true) return;
if(y == n){
if(isclicked == 0 && startedsecond == -1){
isfound =true;
int c=0;
for(int i=0;i<str.length();i++)
if(str[i] == ' ')
c++;
cout << c << endl;
cout << str << endl;
}
return;
}
if(valid(x, y+1) && ns[x][y+1] != 'X' && x == 9)
DFS(x, y+1, second+1, false, -1, str, p);
if(valid(x-1, y+1) && ns[x-1][y+1] != 'X')
DFS(x-1, y+1, second+1, true, isclicked == true ? startedsecond : second, str, p);
else
if(x == 0 && ns[x][y+1] != 'X')
DFS(x, y+1, second+1, true, isclicked == true ? startedsecond : second, str, p);
if(valid(x+1, y+1) && ns[x+1][y+1] != 'X'){
if(isclicked)
str = str + to_string(startedsecond) + " " + to_string(second-startedsecond) + "\n";
DFS(x+1, y+1, second+1, false, -1, str, p+1);
}
}
int main(){
cin >> n;
for(int i=0;i<10;i++){
cin >> ns[i];
}
DFS(9, 0, 0, false, 0, "", 0);
return 0;
}
Compilation message
jetpack.cpp: In function 'void DFS(int, int, int, bool, int, std::__cxx11::string, int)':
jetpack.cpp:25:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<str.length();i++)
~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
680 KB |
Output is correct |
5 |
Correct |
8 ms |
3064 KB |
Output is correct |
6 |
Correct |
13 ms |
7316 KB |
Output is correct |
7 |
Runtime error |
68 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
80 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
89 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
94 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |