Submission #17857

# Submission time Handle Problem Language Result Execution time Memory
17857 2016-01-12T14:16:12 Z Elibay K-th path (IZhO11_kthpath) C++14
0 / 100
329 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;
const int MaxN = 30 + 17, INF = 1e9;
long long n, m, q;

char a[MaxN][MaxN];
vector < string > g[MaxN][MaxN];
int main ()
{
    ios_base :: sync_with_stdio (0);
    #ifdef Elibay
        freopen (".in", "r", stdin);
    #endif
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
        for (int j = 1; j <= m; ++ j)
            cin >> a[i][j];
    cin >> q;
    string w;
    w += a[1][1];
    g[1][1].push_back (w);
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            if (i == 1 && j == 1)
                continue;
            if (i - 1 >= 1)
            {
                for (int k = 0; k < g[i - 1][j].size(); ++ k)
                    g[i][j].push_back (g[i - 1][j][k] + a[i][j]);
            } 
            if (j - 1 >= 1)
            {
                for (int k = 0; k < g[i][j - 1].size(); ++ k)
                    g[i][j].push_back (g[i][j - 1][k] + a[i][j]);
            } 
        }
    }
    -- q;
    sort (g[n][m].begin (), g[n][m].end ());
    cout << g[n][m][q];
    return 0;
}

Compilation message

kthpath.cpp: In function 'int main()':
kthpath.cpp:31:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int k = 0; k < g[i - 1][j].size(); ++ k)
                                   ^
kthpath.cpp:36:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int k = 0; k < g[i][j - 1].size(); ++ k)
                                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2236 KB Output is correct
2 Correct 0 ms 2236 KB Output is correct
3 Correct 0 ms 2380 KB Output is correct
4 Memory limit exceeded 329 ms 262144 KB Memory limit exceeded
5 Halted 0 ms 0 KB -