# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244188 | NONAME | Pohlepko (COCI16_pohlepko) | C++14 | 1091 ms | 65540 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>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
char c[2000][2000];
bool cmp(pair <int, int> x, pair <int, int> y) {
return c[x.first][x.second] < c[y.first][y.second];
}
int main() {
fast_io;
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
cin >> c[i][j];
vector <pair <int, int> > p, np;
p.push_back(make_pair(0, 0));
for (int i = 0; i < n + m - 1; ++i) {
sort(p.begin(), p.end(), cmp);
cout << c[p[0].first][p[0].second];
if (i == n + m - 2)
break;
char ch = 'z';
for (auto j : p) {
int x = j.first, y = j.second;
if (x + 1 < n)
ch = min(ch, c[x + 1][y]);
if (y + 1 < m)
ch = min(ch, c[x][y + 1]);
}
for (auto j : p) {
int x = j.first, y = j.second;
if (x + 1 < n && c[x + 1][y] == ch)
np.push_back(make_pair(x + 1, y));
if (y + 1 < m && c[x][y + 1] == ch)
np.push_back(make_pair(x, y + 1));
}
p = np;
np.clear();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |