# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
963163 | biank | K번째 경로 (IZhO11_kthpath) | C++17 | 1 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 30;
using ll = __int128;
ll dp[MAX_N][MAX_N];
char g[MAX_N][MAX_N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
dp[n - 1][m - 1] = 1;
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
if (i != n - 1) dp[i][j] += dp[i + 1][j];
if (j != m - 1) dp[i][j] += dp[i][j + 1];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> g[i][j];
}
}
long long k;
cin >> k;
string ans = "";
int i = 0, j = 0;
while (i != n - 1 && j != m - 1) {
ans += g[i][j];
if (g[i + 1][j] < g[i][j + 1]) {
if (k <= dp[i + 1][j]) i++;
else k -= dp[i + 1][j], j++;
} else {
if (k <= dp[i][j + 1]) j++;
else k -= dp[i][j + 1], i++;
}
}
while (i != n - 1) ans += g[i][j], i++;
while (j != m) ans += g[i][j], j++;
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |