# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104148 | leonarda | Pohlepko (COCI16_pohlepko) | C++14 | 83 ms | 66560 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
const int maxn = 2000 + 5;
int n, m;
char a[maxn][maxn];
string dp[maxn][maxn];
int nadi(string s, string t) {
for(int i = 0; i < s.size(); ++i)
if(s[i] != t[i])
return i;
return -1; //stringovi su isti
}
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];
dp[0][0].pb(a[0][0]);
for(int i = 1; i < m; ++i)
dp[0][i] = dp[0][i - 1] + a[0][i];
for(int i = 1; i < n; ++i)
dp[i][0] = dp[i - 1][0] + a[i][0];
for(int i = 1; i < n; ++i) {
for(int j = 1; j < m; ++j) {
string s = dp[i - 1][j];
string t = dp[i][j - 1];
int raz = nadi(s, t);
if(raz == -1)
dp[i][j] = s + a[i][j];
else {
if(s[raz] < t[raz])
dp[i][j] = s + a[i][j];
else
dp[i][j] = t + a[i][j];
}
}
}
cout << dp[n - 1][m - 1];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |