| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 895354 | presko | K번째 경로 (IZhO11_kthpath) | C++14 | 1 ms | 348 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
