# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104333 | leonarda | Pohlepko (COCI16_pohlepko) | C++14 | 1079 ms | 25284 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;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
const int maxn = 2000 + 5;
int n, m;
char a[maxn][maxn];
string fuki(string t1, string t2) {
for(int i = 0; i < t1.size(); ++i) {
if(t1[i] < t2[i]) return t1;
if(t2[i] < t1[i]) return t2;
}
return t1;
}
string solve(int x, int y, string dosad) {
// cout << "x " << x << " y " << y << " dosad " << dosad << endl;
if(x == n - 1 and y == m - 1)
return dosad;
else if(x == n - 1 and y != m - 1)
return solve(x, y + 1, dosad + a[x][y + 1]);
else if(x != n - 1 and y == m - 1)
return solve(x + 1, y, dosad + a[x + 1][y]);
else if(x != n - 1 and y != m - 1 and a[x + 1][y] < a[x][y + 1])
return solve(x + 1, y, dosad + a[x + 1][y]);
else if(x != n - 1 and y != m - 1 and a[x][y + 1] < a[x + 1][y])
return solve(x, y + 1, dosad + a[x][y + 1]);
else
return fuki(solve(x, y + 1, dosad + a[x][y + 1]), solve(x + 1, y, dosad + a[x + 1][y]));
}
int main ()
{
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
cin >> a[i][j];
string geez; geez.pb(a[0][0]);
cout << solve(0, 0, geez);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |