# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330926 | 2020-11-26T22:23:22 Z | ZwariowanyMarcin | K-th path (IZhO11_kthpath) | C++14 | 1 ms | 512 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 492 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 492 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 492 KB | Output is correct |
15 | Correct | 1 ms | 492 KB | Output is correct |
16 | Correct | 1 ms | 492 KB | Output is correct |
17 | Correct | 1 ms | 492 KB | Output is correct |
18 | Correct | 1 ms | 512 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |