Submission #895363

#TimeUsernameProblemLanguageResultExecution timeMemory
895363preskoK-th path (IZhO11_kthpath)C++14
0 / 100
1 ms348 KiB
#include<iostream> #include<bits/stdc++.h> #define MAXN 110 using namespace std; char tab[MAXN][MAXN]; long long ways[MAXN][MAXN]; int main() { int n,m; long long k; ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { char c; cin>>c; if(i==1 && j==1)ways[i][j]=1; else ways[i][j]=ways[i-1][j]+ways[i][j-1]; tab[i][j]=c; } } cin>>k; cout<<tab[1][1]; int x=1,y=1; long long l=1; while(x<n || y<m) { bool fl1=0,fl2=0; long long down=0,right=0; if(y<m)right=ways[n-x+1][m-y];//check right else fl1=1; if(x<n)down=ways[n-x][m-y+1];//check down else fl2=1; if(fl1) { x++; cout<<tab[x][y]; } else if(fl2) { y++; cout<<tab[x][y]; } else { if(tab[x][y+1]<=tab[x+1][y]) { long long lim=l+right; if(k<lim){y++;cout<<tab[x][y];} else {x++;l=lim;cout<<tab[x][y];} } else { long long lim=l+down; if(k<lim){x++;cout<<tab[x][y];} else {y++;l=lim;cout<<tab[x][y];} } } } cout<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...