# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443547 | penguinhacker | Pohlepko (COCI16_pohlepko) | C++14 | 18 ms | 12324 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |