# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229990 | osaaateiasavtnl | Pohlepko (COCI16_pohlepko) | C++14 | 56 ms | 22120 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 int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2007;
int n, m;
string a[N];
ii par[N][N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector <ii> c = { {0, 0} };
vector <ii> v = { {0, 1}, {1, 0} };
for (int t = 0; t < n + m - 2; ++t) {
char mn = 'z';
for (auto p : c) {
for (auto e : v) {
int x = p.f + e.f;
int y = p.s + e.s;
if (0 <= x && x < n && 0 <= y && y < m) {
mn = min(mn, a[x][y]);
}
}
}
vector <ii> to;
for (auto p : c) {
for (auto e : v) {
int x = p.f + e.f;
int y = p.s + e.s;
if (0 <= x && x < n && 0 <= y && y < m && a[x][y] == mn) {
par[x][y] = p;
to.app(mp(x, y));
}
}
}
sort(all(to));
to.resize(unique(all(to)) - to.begin());
c = to;
}
int x = n - 1, y = m - 1;
string ans;
while (1) {
ans += a[x][y];
if (x == 0 && y == 0)
break;
tie(x, y) = par[x][y];
}
reverse(all(ans));
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |