# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031059 | 7again | Pohlepko (COCI16_pohlepko) | C++17 | 87 ms | 55212 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>
#define endl "\n"
#define f first
#define s second
#define pb push_back
#define in insert
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)
using namespace std ;
void slv()
{
int n , m ;
cin >> n >> m ;
char a[n][m] ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
cin >> a[i][j] ;
int dp[n][m] ;
fill_n(&dp[0][0] , (n) * (m) , 0) ;
pair <int , int> pos[n][m] ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
{
dp[i][j] += a[i][j] ;
if(i == 0 && j == 0)
continue ;
if(j == 0)
{
dp[i][j] += a[i - 1][j] ;
pos[i][j] = {i - 1 , j} ;
}
else if(i == 0)
{
dp[i][j] += a[i][j - 1] ;
pos[i][j] = {i , j - 1} ;
}
else if(a[i - 1][j] < a[i][j - 1])
{
dp[i][j] += a[i - 1][j] ;
pos[i][j] = {i - 1 , j} ;
}
else
{
dp[i][j] += a[i][j - 1] ;
pos[i][j] = {i , j - 1} ;
}
}
}
pair <int , int> E = {n - 1 , m - 1} ;
vector <char> ans ;
while(1)
{
ans.pb(a[E.f][E.s]) ;
if(E.f + E.s == 0)
break ;
E = pos[E.f][E.s] ;
}
reverse(all(ans)) ;
for(auto t : ans)
cout << t ;
}
main()
{
FAST ;
slv() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |