제출 #33971

#제출 시각아이디문제언어결과실행 시간메모리
33971imeimi2000Paint By Numbers (IOI16_paint)C++14
100 / 100
1916 ms242336 KiB
#include "paint.h" #include <algorithm> #include <cstdlib> using namespace std; typedef long long llong; int n, k; int dp1[200001][101]; int dp2[200002][102]; int dp3[200001][101]; int sumB[200001]; int sumW[200001]; char str[200002]; vector<int> block; string solve_puzzle(string s, vector<int> c) { char trans[256]; trans['.'] = 'N'; trans['X'] = 'B'; trans['_'] = 'W'; n = s.length(); k = c.size(); block.resize(k + 1); for (int i = 1; i <= n; ++i) str[i] = trans[s[i - 1]]; for (int i = 1; i <= k; ++i) block[i] = c[i - 1]; for (int i = 1; i <= n; ++i) { sumB[i] = sumB[i - 1] + (str[i] == 'B'); sumW[i] = sumW[i - 1] + (str[i] == 'W'); } dp1[0][0] = true; for (int i = 1; i <= n; ++i) { dp1[i][0] = (sumB[i] == 0); dp1[i][1] = (i > 1 && dp1[i - 1][1] && str[i] != 'B') || (i >= block[1] && sumW[i] == sumW[i - block[1]] && sumB[i - block[1]] == 0); } for (int i = 2; i <= k; ++i) { for (int j = block[i] + 2; j <= n; ++j) { dp1[j][i] = (j > 1 && str[j] != 'B' && dp1[j - 1][i]) || (j > block[i] + 1 && str[j - block[i]] != 'B' && sumW[j - block[i]] == sumW[j] && dp1[j - block[i] - 1][i - 1]); } } dp2[n + 1][k + 1] = true; for (int i = n; i >= 1; --i) { dp2[i][k + 1] = (sumB[i - 1] == sumB[n]); dp2[i][k] = (i > 1 && dp2[i + 1][k] && str[i] != 'B') || (i <= n - block[k] + 1 && sumW[i - 1] == sumW[i + block[k] - 1] && sumB[i + block[k] - 1] == sumB[n]); } for (int i = k - 1; i > 0; --i) { for (int j = n - block[i] - 1; j > 0; --j) { dp2[j][i] = (j < n && str[j] != 'B' && dp2[j + 1][i]) || (j < n - block[i] && str[j + block[i]] != 'B' && sumW[j + block[i] - 1] == sumW[j - 1] && dp2[j + block[i] + 1][i + 1]); } } if (k == 1) { for (int i = block[1]; i <= n; ++i) { dp3[i][1] = (sumW[i] == sumW[i - block[1]] && sumB[i - block[1]] == 0 && sumB[i] == sumB[n]); dp3[i][1] += dp3[i - 1][1]; } } else { for (int i = 1; i <= n; ++i) { dp3[i][k] = (i > block[k] && dp1[i - block[k] - 1][k - 1] && sumW[i] == sumW[i - block[k]] && sumB[i] == sumB[n] && str[i - block[k]] != 'B'); dp3[i][k] += dp3[i - 1][k]; dp3[i][1] = (i >= block[1] && sumW[i] == sumW[i - block[1]] && sumB[i - block[1]] == 0 && i < n && dp2[i + 2][2] && str[i + 1] != 'B'); dp3[i][1] += dp3[i - 1][1]; } } for (int i = 2; i < k; ++i) { for (int j = 1; j <= n; ++j) { dp3[j][i] = (j > block[i] && j < n && dp1[j - block[i] - 1][i - 1] && dp2[j + 2][i + 1] && sumW[j] == sumW[j - block[i]] && str[j - block[i]] != 'B' && str[j + 1] != 'B'); dp3[j][i] += dp3[j - 1][i]; } } int j; for (int i = 1; i <= n; ++i) { if (str[i] != 'N') continue; for (j = 0; j <= k; ++j) { if (dp1[i - 1][j] && dp2[i + 1][j + 1]) break; } if (j > k) str[i] = 'B'; } for (int i = 1; i <= n; ++i) { if (str[i] != 'N') continue; for (j = 1; j <= k; ++j) { if (dp3[min(n, i + block[j] - 1)][j] - dp3[i - 1][j] != 0) break; } if (j > k) str[i] = 'W'; } string ret = ""; trans['N'] = '?'; trans['B'] = 'X'; trans['W'] = '_'; for (int i = 1; i <= n; ++i) ret.push_back(trans[str[i]]); return ret; }

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

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:24:54: warning: array subscript has type 'char' [-Wchar-subscripts]
  for (int i = 1; i <= n; ++i) str[i] = trans[s[i - 1]];
                                                      ^
paint.cpp:108:57: warning: array subscript has type 'char' [-Wchar-subscripts]
  for (int i = 1; i <= n; ++i) ret.push_back(trans[str[i]]);
                                                         ^
#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...