Submission #967562

#TimeUsernameProblemLanguageResultExecution timeMemory
967562amine_arouaPaint By Numbers (IOI16_paint)C++17
59 / 100
1 ms600 KiB
#pragma once #include <bits/stdc++.h> using namespace std; #define forr(i, x , y) for(int i = x ; i<=y;i++) #define fore(i , x) for(int i = 0 ; i<x;i++) #define forn(i , x ,y) for(int i = x; i>=y;i--) vector<vector<int>> pref; std::string solve_puzzle(std::string s, std::vector<int> c) { int n = (int)s.size(); int K = (int)c.size(); for(auto &C: s) if(C == '.')C='?'; pref.assign(2 , vector<int>(n + 1 , 0)); forr(i , 1 , n) { pref[0][i] = pref[0][i - 1] + (s[i - 1] == '_'); pref[1][i] = pref[1][i - 1] + (s[i - 1] == 'X'); } vector<vector<int>> dpL(n + 1 , vector<int>(K + 1 , 0)) , dpR(n + 2 , vector<int>(K + 1 , 0)); dpL[0][0] = 1; forr(i , 1 , n) { forr(j , 0 , K) { if(j - 1 >= 0) { int l = i - c[j - 1] + 1; int r = i; if(l >= 1) { if(pref[0][r] - pref[0][l - 1] == 0) { if(j == 1) { dpL[i][j]|=dpL[i - c[j - 1]][j -1]; } else { if(i - c[j - 1] - 1 >= 0 && s[i - c[j - 1]] != 'X') { dpL[i][j] |= dpL[i - c[j - 1] - 1][j - 1]; } } } } } if(s[i -1] != 'X') dpL[i][j]|=dpL[i - 1][j]; } } dpR[n + 1][K] = 1; forn(i , n , 1) { forr(j , 0 , K) { if(j + 1 <= K) { int l = i; int r = i + c[j] - 1; if(r <= n) { if(pref[0][r] - pref[0][l - 1] == 0) { if(j == K - 1) { dpR[i][j]|=dpR[i + c[j]][j +1]; } else { if(i + c[j] <= n && s[i + c[j] - 1] != 'X') { dpR[i][j] |= dpR[i + c[j] + 1][j + 1]; } } } } } if(s[i -1] != 'X') dpR[i][j]|=dpR[i + 1][j]; } } vector<int> can_black(n +2 , 0); vector<int> val(n , 0); forr(i , 1 , n) { if(s[i - 1] != 'X') { int cur = 0; forr(k , 0 , K) { cur|=(dpL[i - 1][k] && dpR[i + 1][k]); } if(cur == 1) val[i-1]|=1; } } forr(i , 1 , n) { if(s[i - 1] == '?' || s[i - 1] == 'X') { forr(k , 0 , K - 1) { int lt = i , rt = c[k] + i - 1; if(rt > n) continue; bool checkL = ((i == 1) || s[i - 2] != 'X'); bool checkR = ((rt == n) || s[rt] != 'X'); int dpLeft ; if(i <= 2) dpLeft = (k == 0); else dpLeft = dpL[i - 2][k]; int dpRight; if(rt + 2 > n) dpRight= ((k + 1) == K); else dpRight = dpR[rt + 2][k + 1]; if(checkL && checkR && dpLeft && dpRight && ((pref[0][rt] - pref[0][i - 1]) == 0)) { can_black[lt]++; can_black[min(n + 1, rt + 1)]--; } } } } forr(i , 1 , n) { can_black[i]+=can_black[i - 1]; if(can_black[i]) val[i - 1]|=2; } fore(i , n) { if(val[i] == 1) s[i] = '_'; else if(val[i] == 2) s[i] = 'X'; else s[i] = '?'; } return s; }

Compilation message (stderr)

paint.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...