Submission #317278

#TimeUsernameProblemLanguageResultExecution timeMemory
317278fadi57Pohlepko (COCI16_pohlepko)C++14
10 / 80
454 ms65540 KiB
#include <bits/stdc++.h> using namespace std; const long long mx=3000; const long long mod=1e9+7; typedef long long ll; queue<pair<string,pair<int,int>>>q; int n,m; string a[mx]; int dx[2]={0,1}; int dy[2]={1,0}; string bfs(){ string z=""; z+=a[0][0]; string ans="z"; for(int i=0;i<n+m;i++){ans+='z';} q.push({z,{0,0}}); while(!q.empty()){ pair<string,pair<int,int>>qq; qq=q.front(); q.pop(); int myx=qq.second.first; int myy=qq.second.second; string h=qq.first; if(myx==(n-1)&&myy==(m-1)){ans=min(ans,qq.first);}else{ } for(int i=0;i<2;i++){ int xx=myx+dx[i]; int yy=myy+dy[i]; if(xx<n&&yy<m){ q.push({h+a[xx][yy],{xx,yy}}); } } } return ans; } int main() { cin>>n>>m; for(int i=0;i<n;i++){ cin>>a[i]; } cout<<bfs(); }
#Verdict Execution timeMemoryGrader output
Fetching results...