QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545827#8776. Not Another Constructive!Djangle162857#WA 0ms52052kbC++144.0kb2024-09-03 17:31:232024-09-03 17:31:23

Judging History

你现在查看的是最新测评结果

  • [2024-09-03 17:31:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:52052kb
  • [2024-09-03 17:31:23]
  • 提交

answer

#include <bits/stdc++.h>
#define fir first
#define sec second
#define FINISH cout << "FINISH" << endl;
#define debug(x) cerr << #x << " : = " << endl;
typedef long long ll;
const int inf = 0x7fffffff;
using namespace std;
bool dp[42][2500][410][42];
struct las
{
    short i, j, k;
};
void solve()
{
    short n, kk;
    cin >> n >> kk;
    string ss, s;
    cin >> ss;
    ss = " " + ss;
    s = ss;
    for (int i = 1; i <= n; i++)
    {
        if (s[i] != '?' && s[i] != 'N' && s[i] != 'A' && s[i] != 'C')
            s[i] = 'B';
    }
    dp[0][0][0][0] = 1;
    for (short i = 0; i < n; i++)
    {
        // 位
        for (short r = 0; r <= i; r++)
        {
            // N
            for (short k = 0; k <= (i / 2 + 1) * (i / 2); k++)
            {
                // NA
                for (short j = 0; j <= (i / 3 + 1) * (i / 3 + 1) * (i / 3); j++)
                {
                    // NAC
                    if (!dp[i][j][k][r])
                        continue;
                    // cout << "! " << i << " " << j << " " << k  << " " << r << endl;
                    // 加一个N
                    if (s[i + 1] == '?' || s[i + 1] == 'N') {
                        // cout << "!N" << endl;
                        dp[i + 1][j][k][r + 1] |= dp[i][j][k][r];

                    }
                    // 加一个A
                    if (s[i + 1] == '?' || s[i + 1] == 'A') {
                        // cout << "!A" << endl;
                        dp[i + 1][j][k + r][r] |= dp[i][j][k][r];
                    }
                    // 加一个B
                    if (s[i + 1] == '?' || s[i + 1] == 'B') {
                        // cout << "!B" << endl;
                        dp[i + 1][j][k][r] |= dp[i][j][k][r];
                    }
                    // 加一个C
                    if (s[i + 1] == '?' || s[i + 1] == 'C') {
                        // cout << "!C" << endl;
                        dp[i + 1][j + k][k][r] |= dp[i][j][k][r];
                    }
                }
            }
        }
    }
    string ans = " ";
    int nowi = -1, nowj = -1, nowk = -1;
    for (int j = 0; j <= 400; j++)
    {
        for (int k = 0; k <= 40; k++)
        {
            if (dp[n][kk][j][k])
            {
                nowi = kk, nowj = j, nowk = k;
                break;
            }
        }
        if (nowi != -1)
            break;
    }
    if (nowi == -1)
    {
        cout << "-1" << endl;
        return;
    }
    // cout << s << endl;
    for (int i = n; i >= 1; i--)
    {
        if (s[i] == '?')
        {
            if (dp[i - 1][nowi][nowj][nowk])
            {
                ans.push_back('B');
            }
            else if (dp[i - 1][nowi][nowj][nowk - 1])
            {
                ans.push_back('N');
                nowk--;
            }
            else if (dp[i - 1][nowi][nowj - nowk][nowk])
            {
                ans.push_back('A');
                nowj -= nowk;
            }
            else if (dp[i - 1][nowi - nowj][nowj][nowk])
            {
                ans.push_back('C');
                nowi -= nowj;
            }
        }
        if (s[i] == 'A')
        {
            ans.push_back('A');
            nowj -= nowk;
        }
        if (s[i] == 'B')
        {
            ans.push_back('B');
        }
        if (s[i] == 'C')
        {
            ans.push_back('C');
            nowi -= nowj;
        }
        if (s[i] == 'N')
        {
            ans.push_back('N');
            nowk--;
        }
    }
    string res;
    for (int i = n; i >= 1; i--) {
        res.push_back(ans[i]);
    }
    for (int i = 1; i <= n; i++) {
        if (ss[i] != '?')
            res[i] = ss[i];
    }
    cout << res << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 52052kb

input:

22 2
N??A??????C???????????

output:

NNBAABBBBBCCBBBBBBBBBB

result:

wrong answer incorrect number of subsequences: 3