#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 time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Runtime error |
30 ms |
65536 KB |
Execution killed with signal 9 |
4 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
14 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
32 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
14 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
33 ms |
65536 KB |
Execution killed with signal 9 |
11 |
Runtime error |
32 ms |
65536 KB |
Execution killed with signal 9 |
12 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
13 |
Runtime error |
14 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Runtime error |
13 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Runtime error |
12 ms |
65536 KB |
Execution killed with signal 9 |