Submission #895354

#TimeUsernameProblemLanguageResultExecution timeMemory
895354preskoK-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]; unsigned 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; unsigned long long l=1,r=ways[n][m]; while(x<n || y<n) { bool fl1=0,fl2=0; unsigned 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]) { unsigned long long lim=l+right; if(k<lim){y++;r=lim-1;cout<<tab[x][y];} else {x++;l=lim;cout<<tab[x][y];} } else { unsigned long long lim=l+down; if(k<lim){x++;r=lim-1;cout<<tab[x][y];} else {y++;l=lim;cout<<tab[x][y];} } } } cout<<"\n"; }

Compilation message (stderr)

kthpath.cpp: In function 'int main()':
kthpath.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   53 |                 if(k<lim){y++;r=lim-1;cout<<tab[x][y];}
      |                    ~^~~~
kthpath.cpp:59:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   59 |                 if(k<lim){x++;r=lim-1;cout<<tab[x][y];}
      |                    ~^~~~
kthpath.cpp:28:28: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   28 |     unsigned long long l=1,r=ways[n][m];
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...