Submission #443547

#TimeUsernameProblemLanguageResultExecution timeMemory
443547penguinhackerPohlepko (COCI16_pohlepko)C++14
80 / 80
18 ms12324 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=2000; int n, m; string g[mxN], ans; bool vis[mxN][mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i=0; i<n; ++i) cin >> g[i]; vector<ar<int, 2>> q(1, {0, 0}); while(q.size()) { ans+=g[q.front()[0]][q.front()[1]]; int mn=69; vector<ar<int, 2>> nq; auto ck=[&](int i, int j) { if (i>=n||j>=m||vis[i][j]) return; vis[i][j]=1; int cur=g[i][j]-'a'; if (cur<mn) { mn=cur; nq={{i, j}}; } else if (cur==mn) nq.push_back({i, j}); }; for (ar<int, 2> i : q) { ck(i[0]+1, i[1]); ck(i[0], i[1]+1); } swap(q, nq); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...