Submission #93940

# Submission time Handle Problem Language Result Execution time Memory
93940 2019-01-13T16:01:37 Z ahmedie404 Pohlepko (COCI16_pohlepko) C++14
15 / 80
1000 ms 29816 KB
#include <iostream>

using namespace std;
int n, m;
string a[2000+9];

bool check(int i, int j){
    return i >= 0 && j >= 0 && i < n && j < m;
}

string finds(int i, int j, string s){

    string sol="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    s += a[i][j];

    if( i == n-1 && j == m-1 )
        return s;


    if(check(i, j+1) && string(s+a[i][j+1]) < string(s+a[i+1][j]))
        sol = min(string(finds(i, j+1, s)), sol);
    else if(check(i+1, j) && string(s+a[i][j+1]) < string(s+a[i+1][j]))
        sol = min(string(finds(i+1, j, s)), sol);
    else{
        if(check(i+1, j))
            sol = min(string(finds(i+1, j, s)), sol);
        if(check(i, j+1))
            sol = min(string(finds(i, j+1, s)), sol);
    }

    return sol;

}

int main(){
    cin >> n >> m;
    for(int i=0;i<n;i++) cin >> a[i];

    cout << finds(0, 0, "") << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 41 ms 504 KB Output is correct
4 Execution timed out 1076 ms 376 KB Time limit exceeded
5 Execution timed out 1071 ms 2076 KB Time limit exceeded
6 Execution timed out 1071 ms 2744 KB Time limit exceeded
7 Execution timed out 1067 ms 10696 KB Time limit exceeded
8 Execution timed out 1078 ms 29500 KB Time limit exceeded
9 Execution timed out 1077 ms 476 KB Time limit exceeded
10 Execution timed out 1079 ms 1244 KB Time limit exceeded
11 Execution timed out 1075 ms 3164 KB Time limit exceeded
12 Execution timed out 1083 ms 3524 KB Time limit exceeded
13 Execution timed out 1084 ms 6192 KB Time limit exceeded
14 Execution timed out 1065 ms 29816 KB Time limit exceeded
15 Execution timed out 1075 ms 632 KB Time limit exceeded
16 Execution timed out 1080 ms 12808 KB Time limit exceeded