| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 902547 | LOLOLO | K-th path (IZhO11_kthpath) | C++17 | 2 ms | 600 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sz(x)   (int)(x).size()
#define len(x)  (int)(x).length()
#define cntbit(x)  builtin_popcnt(x)
#define f   first
#define s   second
#define pb  push_back
#define po(x)   (1 << (x))
const int N = 50;
char mat[N][N];
ull dp[N][N][2], num;
string s;
int n, m;
ll cal() {
    memset(dp, 0, sizeof(dp));
    if (mat[1][1] > s[0])
        return 0;
    if (mat[1][1] == s[0]) {
        dp[1][1][1] = 1;
    } else {
        dp[1][1][0] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == 1 && j == 1)
                continue;
            int k = i + j - 2;
            if (s[k] == mat[i][j]) {
                dp[i][j][1] = dp[i - 1][j][1] + dp[i][j - 1][1];
                dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0];
            } else {
                if (s[k] > mat[i][j]) {
                    dp[i][j][0] = dp[i - 1][j][1] + dp[i][j - 1][1] + dp[i][j - 1][0] + dp[i - 1][j][0];
                } else {
                    dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0];
                }
            }
            dp[i][j][0] = min(num + 1, dp[i][j][0]);
            dp[i][j][1] = min(num + 1, dp[i][j][1]);
        }
    }
    return dp[n][m][0] + dp[n][m][1];
}
ll solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            cin >> mat[i][j];
    }
    for (int i = 1; i < n + m; i++)
        s += 'z';
    ll num1;
    cin >> num1;
    num = num1;
    for (int i = 0; i < len(s); i++) {
        char l = 'a', r = 'z', m;
        while (l <= r) {
            m = (l + r) / 2;
            char p = s[i];
            s[i] = m;
            //cout << cal() << " lmao\n";
            if (cal() >= num) {
                r = m - 1;
            } else {
                l = m + 1;
                s[i] = p;
            }
        }
    }
    cout << s << '\n';
    return 0;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        //cout << solve() << '\n';
    }
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
