# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864380 | gutzzy | Pohlepko (COCI16_pohlepko) | C++14 | 134 ms | 4400 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;
int n;
int m;
string ans = "{";
vector<vector<char>> board;
void bt(int i, int j, string cur){
if(i==n-1 and j==m-1){
ans = cur;
return;
}
if(i==n-1){
j++;
cur+=board[i][j];
if(cur<=ans){
ans = cur;
bt(i,j,cur);
}
return;
}
else if(j==m-1){
i++;
cur+=board[i][j];
if(cur<=ans){
ans = cur;
bt(i,j,cur);
}
return;
}
else{
if(board[i+1][j]!=board[i][j+1]){
if(board[i+1][j]<board[i][j+1]) i++;
else j++;
cur += board[i][j];
if(cur<=ans){
ans = cur;
bt(i,j,cur);
}
return;
}
else{
cur += board[i+1][j];
if(cur<=ans){
ans = cur;
bt(i+1,j,cur);
bt(i,j+1,cur);
}
return;
}
}
}
int main(){
cin >> n >> m;
board = vector<vector<char>>(n,vector<char>(m));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin >> board[i][j];
}
}
string c;
c += board[0][0];
bt(0,0,c);
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |