제출 #967520

#제출 시각아이디문제언어결과실행 시간메모리
967520amine_arouaPaint By Numbers (IOI16_paint)C++17
7 / 100
1 ms348 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++) vector<vector<int>> pref; auto compute_dp(int n , int K , string s , vector<int> c) { vector<vector<int>> dp(n + 1 , vector<int>(K + 1 , 0)); dp[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) { dp[i][j]|=dp[i - c[j - 1]][j -1]; } else { if(s[i - c[j - 1]] != 'X') { dp[i][j] |= dp[i - c[j - 1] - 1][j - 1]; } } } } } if(s[i -1] != 'X') dp[i][j]|=dp[i - 1][j]; } } return dp; } 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'); } auto dpL = compute_dp(n , K, s , c); reverse(s.begin() , s.end()); reverse(c.begin() , c.end()); auto dpR = compute_dp(n , K , s , c); reverse(s.begin() , s.end()); reverse(c.begin() , c.end()); reverse(dpR.begin() , dpR.end()); for(auto &v : dpR) reverse(v.begin() , v.end()); 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][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 = (i <= 2 && k == 0); else dpLeft = dpL[i - 2][k]; int dpRight; if(rt + 1 > n) dpRight= (rt + 1 > n && (k + 1) == K); else dpRight = dpR[rt + 1][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; }

컴파일 시 표준 에러 (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...