제출 #244188

#제출 시각아이디문제언어결과실행 시간메모리
244188NONAMEPohlepko (COCI16_pohlepko)C++14
65 / 80
1091 ms65540 KiB
#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 timeMemoryGrader output
Fetching results...