Submission #330926

#TimeUsernameProblemLanguageResultExecution timeMemory
330926ZwariowanyMarcinK-th path (IZhO11_kthpath)C++14
100 / 100
1 ms512 KiB
#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)

kthpath.cpp: In function 'int main()':
kthpath.cpp:45:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |   for (auto [r, c] : lvl[i]) {
      |             ^
kthpath.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |    for (auto [r, k] : lvl[i])
      |              ^
kthpath.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
kthpath.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |   scanf("%s", s[i] + 1);
      |   ~~~~~^~~~~~~~~~~~~~~~
kthpath.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%lld", &k);
      |  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...