Submission #902547

#TimeUsernameProblemLanguageResultExecution timeMemory
902547LOLOLOK-th path (IZhO11_kthpath)C++17
100 / 100
2 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define sz(x) (int)(x).size() #define len(x) (int)(x).length() #define cntbit(x) builtin_popcnt(x) #define f first #define s second #define pb push_back #define po(x) (1 << (x)) const int N = 50; char mat[N][N]; ull dp[N][N][2], num; string s; int n, m; ll cal() { memset(dp, 0, sizeof(dp)); if (mat[1][1] > s[0]) return 0; if (mat[1][1] == s[0]) { dp[1][1][1] = 1; } else { dp[1][1][0] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (i == 1 && j == 1) continue; int k = i + j - 2; if (s[k] == mat[i][j]) { dp[i][j][1] = dp[i - 1][j][1] + dp[i][j - 1][1]; dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0]; } else { if (s[k] > mat[i][j]) { dp[i][j][0] = dp[i - 1][j][1] + dp[i][j - 1][1] + dp[i][j - 1][0] + dp[i - 1][j][0]; } else { dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0]; } } dp[i][j][0] = min(num + 1, dp[i][j][0]); dp[i][j][1] = min(num + 1, dp[i][j][1]); } } return dp[n][m][0] + dp[n][m][1]; } ll solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cin >> mat[i][j]; } for (int i = 1; i < n + m; i++) s += 'z'; ll num1; cin >> num1; num = num1; for (int i = 0; i < len(s); i++) { char l = 'a', r = 'z', m; while (l <= r) { m = (l + r) / 2; char p = s[i]; s[i] = m; //cout << cal() << " lmao\n"; if (cal() >= num) { r = m - 1; } else { l = m + 1; s[i] = p; } } } cout << s << '\n'; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); //cout << solve() << '\n'; } }

Compilation message (stderr)

kthpath.cpp: In function 'll solve()':
kthpath.cpp:78:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   78 |             if (cal() >= num) {
      |                 ~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...