제출 #287141

#제출 시각아이디문제언어결과실행 시간메모리
287141SamAndPaint By Numbers (IOI16_paint)C++17
0 / 100
2 ms1152 KiB
#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])
{
    memset(dp, false, sizeof dp);
    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][k - 1][0] && s[l][k][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)
    {
        if (a[i] != '.')
            continue;
        a[i] = '_';
        stg(p);
        a[i] = '.';
        if (p[n][k][0] || p[n][k][1])
            z2[i] = true;
        else
            z2[i] = false;
    }

    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;
}

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

paint.cpp: In function 'void stg(bool (*)[103][2])':
paint.cpp:20:30: warning: 'sizeof' on array function parameter 'dp' will return size of 'bool (*)[103][2]' [-Wsizeof-array-argument]
   20 |     memset(dp, false, sizeof dp);
      |                              ^~
paint.cpp:18:15: note: declared here
   18 | void stg(bool dp[N][K][2])
      |          ~~~~~^~~~~~~~~~~
paint.cpp:20:23: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
   20 |     memset(dp, false, sizeof dp);
      |                       ^~~~~~~~~
#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...