Submission #864380

#TimeUsernameProblemLanguageResultExecution timeMemory
864380gutzzyPohlepko (COCI16_pohlepko)C++14
5 / 80
134 ms4400 KiB
#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 timeMemoryGrader output
Fetching results...