제출 #823218

#제출 시각아이디문제언어결과실행 시간메모리
823218Alihan_8Paint By Numbers (IOI16_paint)C++17
80 / 100
2057 ms1340 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define pb push_back #define ln '\n' //#define int long long template <class _T> bool chmin(_T &x, const _T &y){ bool flag = false; if ( x > y ){ x = y; flag |= true; } return flag; } template <class _T> bool chmax(_T &x, const _T &y){ bool flag = false; if ( x < y ){ x = y; flag |= true; } return flag; } string solve_puzzle(string s, vector<int> c) { int n = (int)s.size(), m = (int)c.size(); auto ok = [&](string s){ vector <vector<int>> dp(n + 1, vector <int> (m + 1)); dp[0][0] = true; vector <int> pf(n + 1); for ( int i = 0; i < n; i++ ){ pf[i + 1] = pf[i] + (s[i] == '_'); } auto get = [&](int l, int r){ return pf[r] - pf[l - 1]; }; s = '#' + s; for ( int i = 1; i <= n; i++ ){ for ( int j = 0; j <= m; j++ ){ if ( s[i] != 'X' ){ dp[i][j] |= dp[i - 1][j]; } if ( !j ) continue; int k = i - c[j - 1]; if ( k >= 0 && !get(k + 1, i) ){ if ( !k and j <= 1 ){ dp[i][j] = true; } else if ( k and s[k] != 'X' ){ dp[i][j] |= dp[k - 1][j - 1]; } } } } return dp[n][m]; }; string ans = s; for ( int i = 0; i < n; i++ ){ if ( s[i] != '.' ){ continue; } for ( auto j: {'_', 'X'} ){ s[i] = j; if ( ok(s) ){ if ( ans[i] != '.' ){ ans[i] = '?'; } else ans[i] = j; } } s[i] = '.'; } return ans; }
#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...