Submission #1071757

#TimeUsernameProblemLanguageResultExecution timeMemory
1071757TheQuantiXPaint By Numbers (IOI16_paint)C++17
59 / 100
2 ms604 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; using ll = long long; constexpr ll MOD = 1000000007; ll n, m, q, k, x, y, a, b, c; vector< vector<ll> > do_dp(string &s, vector<int> &c) { vector< vector<ll> > dp1(m + 1, vector<ll> (n + 1)); vector<ll> vec(1, 0); for (int i = 0; i < n; i++) { if (s[i] == '_') { vec.push_back(i + 1); } } vector<ll> vec2(1, 0); for (int i = 0; i < n; i++) { if (s[i] == 'X') { vec2.push_back(i + 1); } } for (int j = 0; j <= m; j++) { for (int i = 0; i <= n; i++) { if (j == 0) { dp1[j][i] = ((i == 0 || (vec2.size() == 1 || vec2[1] > i)) ? 1 : 0); // cout << dp1[j][i] << '\n'; continue; } if (i == 0) { dp1[j][i] = 0; continue; } if (i >= c[j - 1] && i - vec[(upper_bound(vec.begin(), vec.end(), i) - vec.begin()) - 1] >= c[j - 1] && (i <= c[j - 1] + 1 || s[i - c[j - 1] - 1] != 'X') && (i == n || s[i] != 'X')) { if (j == 1) { dp1[j][i] = ((vec2.size() == 1 || vec2[1] > i - c[j - 1]) ? 1 : 0); // cout << j << ' ' << i << ' ' << vec2[1] << ' ' << i - c[j - 1] << '\n'; } if (j > 1 && i >= c[j - 1] + 1) { for (int k = max(0LL, vec2[(upper_bound(vec2.begin(), vec2.end(), i) - vec2.begin()) - 1] - c[j - 1] - 1); k <= i - c[j - 1] - 1; k++) { dp1[j][i] += dp1[j - 1][k]; dp1[j][i] %= MOD; } } if (j == m && vec2[vec2.size() - 1] > i) { dp1[j][i] = 0; } } // dp1[j][i] += dp1[j][i - 1]; // dp1[j][i] %= MOD; } } for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { dp1[j][i] += dp1[j][i - 1]; dp1[j][i] %= MOD; // cout << j << ' ' << i << ' ' << dp1[j][i] << '\n'; } // cout << '\n'; } // cout << '\n'; return dp1; } string solve_puzzle(string s, vector<int> c) { n = s.size(); m = c.size(); string ans; auto dp1 = do_dp(s, c); reverse(c.begin(), c.end()); reverse(s.begin(), s.end()); auto dp2 = do_dp(s, c); reverse(c.begin(), c.end()); reverse(s.begin(), s.end()); vector<ll> vec(1, 0); for (int i = 0; i < n; i++) { if (s[i] == '_') { vec.push_back(i + 1); } } vector<ll> cnt(n + 1); for (int j = 0; j < m; j++) { for (int i = c[j] + (j != 0 ? 1 : 0); (n + 1 - i) - 1 - (j != m - 1 ? 1 : 0) >= 0; i++) { // cout << j << ' ' << i << '\n'; if (i - vec[(upper_bound(vec.begin(), vec.end(), i) - vec.begin()) - 1] < c[j]) { continue; } if (i > c[j] && s[i - c[j] - 1] == 'X') { continue; } if (i < n && s[i] == 'X') { continue; } // cout << j << ' ' << i << endl; ll num = dp1[j][i - c[j] - (j != 0 ? 1 : 0)]; // cout << num << endl; // cout << m - 1 - j << ' ' << (n + 1 - i) - 1 - (j != m - 1 ? 1 : 0) << endl; num *= dp2[m - 1 - j][(n + 1 - i) - 1 - (j != m - 1 ? 1 : 0)]; num %= MOD; // cout << num << endl; cnt[i - c[j]] += num; cnt[i - c[j]] %= MOD; cnt[i] += MOD - num; cnt[i] %= MOD; // cout << '\n'; } } // cout << "DEBUG" << endl; for (int i = 0; i < n; i++) { cnt[i] %= MOD; // cout << i << ' ' << cnt[i] << endl; cnt[i + 1] += cnt[i]; // cout << i << endl; if (cnt[i] == 0) { ans += '_'; } else if (cnt[i] == dp1[m][n]) { ans += 'X'; } else { ans += '?'; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...