이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
const int N = 200005, K = 103;
int n;
string a;
int k;
vector<int> c;
bool p[N][K][2], s[N][K][2];
void stg(bool dp[N][K][2])
{
for (int i = 0; i <= n; ++i)
{
for (int j = 0; j <= k; ++j)
{
for (int z = 0; z < 2; ++z)
dp[i][j][z] = false;
}
}
int p[N] = {};
dp[0][0][0] = true;
for (int i = 1; i <= n; ++i)
{
p[i] = p[i - 1];
if (a[i] == '_')
p[i]++;
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j <= k; ++j)
{
for (int z = 0; z < 2; ++z)
{
if (!dp[i][j][z])
continue;
if (a[i + 1] != 'X')
dp[i + 1][j][0] = true;
if (!z)
{
if (j != k)
{
if (i + c[j + 1] <= n)
{
if (p[i + c[j + 1]] - p[i] == 0)
{
dp[i + c[j + 1]][j + 1][1] = true;
}
}
}
}
}
}
}
}
bool z1[N], z2[N];
int q[N];
std::string solve_puzzle(std::string s_, std::vector<int> c_)
{
n = sz(s_);
a = s_;
k = sz(c_);
c = c_;
reverse(all(a));
a += '@';
reverse(all(a));
reverse(all(c));
c.push_back(0);
reverse(all(c));
stg(p);
reverse(all(a));
a.pop_back();
reverse(all(a));
a += '@';
reverse(all(a));
reverse(all(c));
c.pop_back();
reverse(all(c));
c.push_back(0);
reverse(all(c));
stg(s);
reverse(all(a));
a.pop_back();
reverse(all(a));
a += '@';
reverse(all(a));
reverse(all(c));
c.pop_back();
reverse(all(c));
c.push_back(0);
reverse(all(c));
for (int i = 0, j = n + 1; i <= j; ++i, --j)
{
for (int u = 0; u <= k; ++u)
{
swap(s[i][u], s[j][u]);
}
}
for (int u = 1; u <= n + 1; ++u)
{
for (int i = 0, j = k + 1; i <= j; ++i, --j)
{
swap(s[u][i], s[u][j]);
}
}
for (int j = 1; j <= k; ++j)
{
for (int l = 1; l <= n - c[j] + 1; ++l)
{
int r = l + c[j] - 1;
if (p[l - 1][j - 1][0] && s[l][j][1])
{
++q[l];
--q[r + 1];
}
}
}
for (int i = 1; i <= n; ++i)
{
q[i] += q[i - 1];
if (q[i])
z1[i] = true;
else
z1[i] = false;
}
for (int i = 1; i <= n; ++i)
{
z2[i] = false;
for (int j = 0; j <= k; ++j)
{
if (p[i][j][0] && s[i][j + 1][0])
{
z2[i] = true;
break;
}
}
}
string ans;
for (int i = 1; i <= n; ++i)
{
if (a[i] != '.')
{
ans.push_back(a[i]);
continue;
}
if (z1[i] && z2[i])
ans.push_back('?');
else if (z1[i])
ans.push_back('X');
else
ans.push_back('_');
}
return ans;
}
# | 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... |