Submission #488985

#TimeUsernameProblemLanguageResultExecution timeMemory
488985SirCovidThe19thK-th path (IZhO11_kthpath)C++17
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n, m; ll k, ways[35][35], choose[65][65]; pair<ll, ll> range; char A[35][35]; vector<char> ans; int main(){ cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> A[i][j]; cin >> k; for (int i = 0; i < 65 and (choose[i][0] = 1); i++) for (int j = 1; j <= i; j++) choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1]; ans.push_back(A[1][1]); ways[1][1] = 1; range = {1, choose[n + m - 2][n - 1]}; for (int len = 2; len <= n + m - 1; len++){ vector<pair<int, int>> test; ll rangeSt = range.first, tot = 0; for (int i = min(len, n), j = max(len - n + 1, 1); i and j <= m; i--, j++){ if (ways[i - 1][j] or ways[i][j - 1]){ //potential valid spot test.push_back({i, j}); ways[i][j] += ways[i - 1][j] + ways[i][j - 1]; } } for (char c = 'a'; c <= 'z'; c++){ for (auto [i, j] : test) if (A[i][j] == c) tot += ways[i][j] * choose[(n - i) + (m - j)][(m - j)]; for (auto [i, j] : test) if (A[i][j] == c){ pair<ll, ll> R = {rangeSt, rangeSt + tot - 1}; if (k >= R.first and k <= R.second){ if (ans.size() < len) ans.push_back(c); range = R; } else ways[i][j] = 0; //range is bad } rangeSt += tot; tot = 0; } } for (char c : ans) cout<<c; }

Compilation message (stderr)

kthpath.cpp: In function 'int main()':
kthpath.cpp:34:36: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |                     if (ans.size() < len) ans.push_back(c);
      |                         ~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...