This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
using namespace std;
/// 13:00
int sum[1 << 18],b[1 << 18],w[1 << 18];
bitset<105>dp[1 << 18],rdp[1 << 18];
string solve_puzzle(string s, vector<int>c)
{
int n = sz(s);
int k = sz(c);
for(int i = 1;i <= n;i++)
{
if(s[i - 1] == '_') sum[i] = 1;
sum[i] += sum[i - 1];
}
dp[0][0] = 1;
for(int i = 1;i <= n;i++)
{
if(s[i - 1] != 'X') for(int j = 0;j <= k;j++) dp[i][j] = dp[i - 1][j];
for(int j = 1;j <= k;j++)
{
int len = c[j - 1];
if(len > i) continue;
if(sum[i] - sum[i - len]) continue;
if((i - len) && s[i - len - 1] == 'X') continue;
if(i - len == 0)
{
if(j != 1) continue;
}
else if(!dp[i - len - 1][j - 1]) continue;
dp[i][j] = 1;
}
}
rdp[n + 1][k + 1] = 1;
for(int i = n;i >= 1;i--)
{
if(s[i - 1] != 'X') for(int j = 1;j <= k + 1;j++) rdp[i][j] = rdp[i + 1][j];
for(int j = 1;j <= k;j++)
{
int len = c[j - 1];
if(i + len - 1 > n) continue;
if(sum[i + len - 1] - sum[i - 1]) continue;
if(i + len <= n && s[i + len - 1] == 'X') continue;
if(i + len == n + 1)
{
if(j != k) continue;
}
else if(!rdp[i + len + 1][j + 1]) continue;
rdp[i][j] = 1;
}
//for(int j = k + 1;j >= 1;j--) cerr << i << ' ' << j << ' ' << rdp[i][j] << '\n';
}
for(int i = 1;i <= n;i++)
{
if(s[i - 1] != '.') continue;
for(int j = 0;j <= k;j++)
{
if(dp[i - 1][j] && rdp[i + 1][j + 1]) w[i] = 1;
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= k;j++)
{
int len = c[j - 1];
if(len > i) continue;
if(sum[i] - sum[i - len]) continue;
if((i - len) && s[i - len - 1] == 'X') continue;
if(i - len == 0)
{
if(j != 1) continue;
}
else if(!dp[i - len - 1][j - 1]) continue;
if(i < n && s[i] == 'X') continue;
if(i == n)
{
if(j != k) continue;
}
else if(!rdp[i + 2][j + 1]) continue;
b[i - len + 1]++;
b[i + 1]--;
}
}
string ans = "";
for(int i = 1;i <= n;i++)
{
b[i] += b[i - 1];
if(s[i - 1] != '.')
{
ans += s[i - 1];
continue;
}
if(b[i] && w[i]) ans += '?';
else if(b[i]) ans += 'X';
else if(w[i]) ans += '_';
}
return ans;
}
Compilation message (stderr)
paint.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |