제출 #243698

#제출 시각아이디문제언어결과실행 시간메모리
243698LawlietPaint By Numbers (IOI16_paint)C++17
100 / 100
1037 ms90224 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const int MAXK = 110; const int MAXN = 200010; int n, k; int sWhite[MAXN]; int canWhite[MAXN]; int canBlack[MAXN]; bool prefix[MAXN][MAXK][2]; bool suffix[MAXN][MAXK][2]; int qtdWhite(int L, int R) { return sWhite[R] - sWhite[L - 1]; } string solve_puzzle(string s, vector<int> c) { n = (int)s.size(); k = (int)c.size(); c.insert( c.begin() , -1 ); s.insert( s.begin() , 'o' ); for(int i = 1 ; i <= n ; i++) { sWhite[i] = sWhite[i - 1]; if( s[i] == '_' ) sWhite[i]++; } prefix[0][0][0] = prefix[0][0][1] = true; suffix[n + 1][k + 1][0] = suffix[n + 1][k + 1][1] = true; for(int j = 0 ; j <= k ; j++) { for(int i = 1 ; i <= n ; i++) { if( s[i] == '_' || s[i] == '.' ) { prefix[i][j][0] = prefix[i - 1][j][1]; prefix[i][j][1] = prefix[i - 1][j][1]; } if( j == 0 || i - c[j] < 0 ) continue; if( qtdWhite( i - c[j] + 1 , i ) != 0 ) continue; if( s[i] == 'X' || s[i] == '.' ) prefix[i][j][1] = prefix[i][j][1] || prefix[i - c[j]][j - 1][0]; } } for(int j = k + 1 ; j > 0 ; j--) { for(int i = n ; i > 0 ; i--) { if( s[i] == '_' || s[i] == '.' ) { suffix[i][j][0] = suffix[i + 1][j][1]; suffix[i][j][1] = suffix[i + 1][j][1]; } if( j == k + 1 || i + c[j] > n + 1 ) continue; if( qtdWhite( i , i + c[j] - 1 ) != 0 ) continue; if( s[i] == 'X' || s[i] == '.' ) suffix[i][j][1] = suffix[i][j][1] || suffix[i + c[j]][j + 1][0]; } } for(int i = 1 ; i <= n ; i++) for(int j = 0 ; j <= k ; j++) if( prefix[i - 1][j][1] && suffix[i + 1][j + 1][1] ) canWhite[i]++; for(int j = 1 ; j <= k ; j++) { int sum = 0; for(int R = 1 ; R <= n ; R++) { int L = R - c[j] + 1; if( L <= 0 || qtdWhite( L , R ) != 0 ) continue; if( prefix[L - 1][j - 1][0] && suffix[R + 1][j + 1][0] ) { canBlack[L]++; canBlack[R + 1]--; } } } for(int i = 1 ; i <= n ; i++) canBlack[i] += canBlack[i - 1]; string ans; for(int i = 1 ; i <= n ; i++) { if( s[i] != '.' ) { ans.push_back( s[i] ); continue; } if( canWhite[i] > 0 && canBlack[i] > 0 ) ans.push_back( '?' ); if( canWhite[i] > 0 && canBlack[i] == 0 ) ans.push_back( '_' ); if( canWhite[i] == 0 && canBlack[i] > 0 ) ans.push_back( 'X' ); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:78:7: warning: unused variable 'sum' [-Wunused-variable]
   int sum = 0;
       ^~~
#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...