# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
317278 | fadi57 | Pohlepko (COCI16_pohlepko) | C++14 | 454 ms | 65540 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;
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |