# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330926 | ZwariowanyMarcin | K-th path (IZhO11_kthpath) | C++14 | 1 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
using ll = long long;
using namespace std;
const int N = 100;
const ll INF = 1LL << 60;
void add(ll &a, ll b) {
a += b;
a = min(a, INF);
}
ll qq(ll a, ll b) {
if (a > INF / b) return INF;
return a * b;
}
int n, m;
char s[N][N];
ll dp[N][N], k, C[N][N];
vector <pair<int, int>> lvl[N];
int main() {
for (int i = 0; i < N; ++i) {
C[i][0] = C[i][i] = 1;
for (int j = 1; j < i; ++j)
C[i][j] = min(C[i - 1][j - 1] + C[i - 1][j], INF);
}
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%s", s[i] + 1);
for (int j = 1; j <= m; ++j)
lvl[i + j].pb({i, j});
}
scanf("%lld", &k);
dp[1][1] = 1;
printf("%c", s[1][1]);
for (int i = 3; i <= n + m; ++i) {
ll cnt[26]{};
for (auto [r, c] : lvl[i]) {
int x = n - r, y = m - c;
add(cnt[s[r][c] - 'a'], qq(dp[r - 1][c] + dp[r][c - 1], C[x + y][x]));
}
for (int c = 0; c < 26; ++c) {
if (cnt[c] < k) {
k -= cnt[c];
continue;
}
for (auto [r, k] : lvl[i])
if (s[r][k] - 'a' == c)
dp[r][k] = min(INF, dp[r - 1][k] + dp[r][k - 1]);
printf("%c", (char)('a' + c));
break;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |