# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864388 | Ariadna | Pohlepko (COCI16_pohlepko) | C++14 | 1099 ms | 65536 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;
int n, m;
vector < vector < char > > grid;
void bfs() {
queue < pair < pair < int, int >, int > > q;
q.push(make_pair(make_pair(0, 0), 0));
vector < char > min_char(n + m - 1, 'z');
min_char[0] = grid[0][0];
while (!q.empty()) {
int i = q.front().first.first;
int j = q.front().first.second;
int d = q.front().second;
q.pop();
if (grid[i][j] != min_char[d]) continue;
if (i < n - 1) {
q.push(make_pair(make_pair(i + 1, j), d + 1));
min_char[d + 1] = min(min_char[d + 1], grid[i + 1][j]);
}
if (j < m - 1) {
q.push(make_pair(make_pair(i, j + 1), d + 1));
min_char[d + 1] = min(min_char[d + 1], grid[i][j + 1]);
}
}
for (int i = 0; i < n + m - 1; ++i) {
cout << min_char[i];
}
cout << '\n';
}
int main()
{
cin >> n >> m;
grid = vector < vector < char > >(n, vector < char >(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> grid[i][j];
}
}
bfs();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |