Submission #895355

# Submission time Handle Problem Language Result Execution time Memory
895355 2023-12-29T19:28:19 Z presko K-th path (IZhO11_kthpath) C++14
0 / 100
1 ms 348 KB
#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,r=ways[n][m];
    while(x<n || y<n)
    {
        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++;r=lim-1;cout<<tab[x][y];}
                else {x++;l=lim;cout<<tab[x][y];}
            }
            else
            {
                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

kthpath.cpp: In function 'int main()':
kthpath.cpp:28:19: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   28 |     long long l=1,r=ways[n][m];
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -