Submission #93874

# Submission time Handle Problem Language Result Execution time Memory
93874 2019-01-12T16:34:20 Z ahmedie404 Jetpack (COCI16_jetpack) C++14
48 / 80
1000 ms 66560 KB
#include <iostream>
#include <algorithm>

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){

    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:24: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 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 12 ms 3064 KB Output is correct
6 Correct 775 ms 7420 KB Output is correct
7 Runtime error 315 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Execution timed out 1079 ms 26352 KB Time limit exceeded
9 Execution timed out 1083 ms 27952 KB Time limit exceeded
10 Runtime error 132 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)