Submission #568150

#TimeUsernameProblemLanguageResultExecution timeMemory
568150hoanghq2004Paint By Numbers (IOI16_paint)C++14
100 / 100
305 ms174336 KiB
#include <bits/stdc++.h> #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "paint.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5 + 10; const int mod = 1e9 + 7; int n; int f[N][110], g[N][110]; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int sum[N]; string solve_puzzle(string s, vector<int> c) { int n = s.size(); int m = c.size(); for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (s[i - 1] == '_'); f[0][0] = 1; g[n + 1][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= m; ++j) { if (s[i - 1] != 'X') f[i][j] = f[i - 1][j]; if (j > 0 && i >= c[j - 1] && sum[i] == sum[i - c[j - 1]]) { if (i == c[j - 1]) { if (j == 1) add(f[i][j], 1); } else if (s[i - c[j - 1] - 1] != 'X') add(f[i][j], f[i - c[j - 1] - 1][j - 1]); } } } for (int i = n; i >= 1; --i) { for (int j = 0; j <= m; ++j) { if (s[i - 1] != 'X') g[i][j] = g[i + 1][j]; if (j > 0 && i + c[m - j] - 1 <= n && sum[i + c[m - j] - 1] == sum[i - 1]) { if (i + c[m - j] == n + 1) { if (j == 1) add(g[i][j], 1); } else if (s[i + c[m - j] - 1] != 'X') add(g[i][j], g[i + c[m - j] + 1][j - 1]); } } } int tot = f[n][m]; for (int i = 1; i <= n; ++i) { if (s[i - 1] != '.') continue; int cur = 0; for (int j = 0; j <= m; ++j) { add(cur, 1LL * f[i - 1][j] * g[i + 1][m - j] % mod); } if (cur == 0) s[i - 1] = 'X'; else if (cur == tot) s[i - 1] = '_'; else s[i - 1] = '?'; } return s; } // // //const int S_MAX_LEN = 200 * 1000; //char buf[S_MAX_LEN + 1]; // //int main() { // assert(1 == scanf("%s", buf)); // std::string s = buf; // int c_len; // assert(1 == scanf("%d", &c_len)); // std::vector<int> c(c_len); // for (int i = 0; i < c_len; i++) { // assert(1 == scanf("%d", &c[i])); // } // std::string ans = solve_puzzle(s, c); // // // printf("%s\n", ans.data()); // return 0; //}

Compilation message (stderr)

paint.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
paint.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#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...