Submission #865652

#TimeUsernameProblemLanguageResultExecution timeMemory
865652vjudge1Pohlepko (COCI16_pohlepko)C++11
0 / 80
33 ms65536 KiB
#include <bits/stdc++.h> #define sts stable_sort #define B begin() #define rB rbegin() #define E end() #define rE rend() #define F first #define S second #define pb push_back #define ppb pop_back() #define pf push_front #define eb = emplace_back #define ppf = pop_front() #define L(x) ((x)<<1) #define pii pair<int, int> #define rB rbegin() #define rE rend() using namespace std; using ll = long long; using ull = unsigned long long; using ui = unsigned int; const int MAXN = 2 * 1e3 + 1; const int MOD = 1e9 + 7; const int inf = INT_MAX; const ll INF = LONG_LONG_MAX; char v[MAXN][MAXN]; string ans[MAXN][MAXN]; int n, m; void bfs(){ queue<pair<pair<int, int>, string> > q; string aux = ""; aux.pb(v[1][1]); q.push({{1, 1}, aux}); while(!q.empty()){ int x = q.front().F.F, y = q.front().F.S; string s = q.front().S; q.pop(); if(x > n || y > m)continue; if(ans[x][y] == ""){ ans[x][y] = s; }else if(ans[x][y] < s)continue; ans[x][y] = s; q.push({{x + 1, y}, s + v[x + 1][y]}); q.push({{x, y + 1}, s + v[x][y + 1]}); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> v[i][j]; } } bfs(); cout << ans[n][m] << '\n'; } /** */
#Verdict Execution timeMemoryGrader output
Fetching results...