Submission #243437

#TimeUsernameProblemLanguageResultExecution timeMemory
243437VEGAnnPohlepko (COCI16_pohlepko)C++14
80 / 80
82 ms8184 KiB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define i2 array<int,2>
#define PB push_back
using namespace std;
const int N = 2010;
const int oo = 2e9;
vector<i2> vc, nw;
char c[N][N];
int n, m;
string s = "";

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        cin >> c[i][j];

    vc.PB({0, 0});

    while (sz(vc) > 0){
        char mn = 'z';

        nw.clear();

        for (i2 cr : vc)
            mn = min(mn, c[cr[0]][cr[1]]);

        for (i2 cr : vc){
            int x = cr[0], y = cr[1];

            if (c[x][y] != mn) continue;

            if (x < n - 1)
                nw.PB({x + 1, y});
            if (y < m - 1)
                nw.PB({x, y + 1});
        }

        s += mn;

        sort(all(nw));
        nw.resize(unique(all(nw)) - nw.begin());

        vc = nw;
    }

    cout << s;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...