제출 #1246648

#제출 시각아이디문제언어결과실행 시간메모리
1246648LemserPaint By Numbers (IOI16_paint)C++20
90 / 100
415 ms589824 KiB
#include "paint.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #pragma GCC target("popcnt") using namespace std; using ll = long long; using ull = unsigned long long; using lld = long double; using ii = pair<int,int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; using vpll = vector<pll>; using vlld = vector<lld>; #define all(x) x.begin(),x.end() #define lsb(x) x&(-x) #define gcd(a,b) __gcd(a,b) #define sz(x) (int)x.size() #define mp make_pair #define pb push_back #define fi first #define se second #define fls cout.flush() #define fore(i, l, r) for (auto i = l; i < r; i++) #define fo(i, n) fore (i, 0, n) #define forex(i, r, l) for (auto i = r-1; i >= l; i--) #define ffo(i, n) forex (i, n, 0) bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; } bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; } const ll INF = 1e18; const int mod = 1e9 + 7, LOG = 20; bool is_possible (ll n, ll k, string s, vector<int> c) { vector<vll> dp(n+3, vll(k+3, 0)); s = 'w' + s; {auto d = c; c = vector<int>(1, 0); fo (i, k) c.pb(d[i]);} dp[0][0] = 1; fore (i, 1, n+1) { fo (j, k+1) { // elegir nada dp[i][j] |= (dp[i-1][j] && (s[i] != 'X' ? 1 : 0)); // elegir substring if (c[j] <= i && j > 0) { bool ok = 1; forex (x, i+1, i-c[j]+1) ok &= (s[x] != '_'); ok &= (s[i-c[j]] != 'X'); if (c[j] == i) dp[i][j] |= ((j == 1) && ok); else dp[i][j] |= (dp[i-c[j]-1][j-1] && ok); } // ___XXX } } return dp[n][k]; } void prec (ll n, ll k, string s, vector<int> &c, vector<vector<vll>> &dppref, vector<vector<vll>> &dpsuf, vll &pf) { s = 'w' + s + 'w'; {auto d = c; c = vector<int>(1, 0); fo (i, k) c.pb(d[i]);} fore (i, 1, n+1) pf[i] = pf[i-1] + (s[i] == '_'); dppref[0][0][0] = 1; dppref[0][0][1] = 1; fore (i, 1, n+1) { fo (j, k+1) { // elegir nada dppref[i][j][0] |= ((dppref[i-1][j][0] || dppref[i-1][j][1]) && (s[i] != 'X' ? 1 : 0)); // elegir substring if (c[j] <= i && j > 0) { bool ok = (pf[i] - pf[i-c[j]] == 0 ? 1 : 0); ok &= (s[i-c[j]] != 'X'); if (c[j] == i) dppref[i][j][1] |= ((j == 1) && ok); else dppref[i][j][1] |= (dppref[i-c[j]][j-1][0] && ok); } } } dpsuf[n+1][0][0] = 1; dpsuf[n+1][0][1] = 1; forex (i, n+1, 1) { fo (j, k+1) { // elegir nada dpsuf[i][j][0] |= ((dpsuf[i+1][j][0] || dpsuf[i+1][j][1]) && (s[i] != 'X' ? 1 : 0)); // elegir substring if (c[k-j+1] <= n - i + 1 && j > 0) { bool ok = (pf[i+c[k-j+1]-1] - pf[i-1] == 0 ? 1 : 0); ok &= (s[i+c[k-j+1]] != 'X'); if (c[k-j+1] == n - i + 1) dpsuf[i][j][1] |= ((j == 1) && ok); else dpsuf[i][j][1] |= (dpsuf[i+c[k-j+1]][j-1][0] && ok); } } } } string solve_puzzle(string s, vector<int> c) { ll n = s.size(), k = c.size(); string ans = s; vector<vector<vll>> dppref(n+3, vector<vll>(k+3, vll(2, 0ll))), dpsuf(n+3, vector<vll>(k+3, vll(2, 0ll))); vector<vll> func(k+3, vll(n+3, 0ll)); vll pf(n+3, 0ll); prec(n, k, s, c, dppref, dpsuf, pf); fore (j, 1, k+1) { fore (i, 1, n+1) { func[j][i] = (dppref[i][j][1] && dpsuf[i+1][k-j][0]); func[j][i] += func[j][i-1]; } } fo (i, n) { if (s[i] != '.') continue; // cout << "Indice " << i << '\n'; s[i] = 'X'; // cout << "checar con X\n"; bool ok = 0; // j = el indice del substring que uso que contenga a i fore (j, 1, k+1) { ok |= (func[j][min(ll(i+c[j]), n)] > func[j][i] ? 1 : 0); } // cout << ok << '\n'; if (ok) ans[i] = 'X'; // cout << "checar con Y\n"; ok = 0; s[i] = '_'; fo (j, k+1) { ok |= (dppref[i+1][j][0] && (dpsuf[i+2][k-j][0] || dpsuf[i+2][k-j][1])); } if (ok) ans[i] = (ans[i] == 'X' ? '?' : '_'); s[i] = '.'; } return ans; }

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

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