QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545884#8776. Not Another Constructive!Djangle162857#WA 3ms83380kbC++145.3kb2024-09-03 17:55:282024-09-03 17:55:28

Judging History

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

  • [2024-09-03 17:55:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:83380kb
  • [2024-09-03 17:55:28]
  • 提交

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;
#define short int
bool dp[42][2510][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;
    int maxj = 0, maxk = 0, maxr = 0;
    for (short i = 0; i < n; i++)
    {
        // 位
        for (short r = 0; r <= maxr; r++)
        {
            // N
            for (short k = 0; k <= maxk; k++)
            {
                // NA
                for (short j = 0; j <= maxj; j++)
                {
                    // NAC
                    if (!dp[i][j][k][r])
                        continue;
                    // cout << "! " << i << " " << j << " " << k  << " " << r << endl;
                    // 加一个N

                    switch(s[i+1]) {
                        case '?':
                            dp[i + 1][j][k][r + 1] =
                            dp[i + 1][j][k + r][r] =
                            dp[i + 1][j][k][r] =
                            dp[i + 1][j + k][k][r] = 1;
                            maxj = max(maxj, j + k);
							maxk = max(maxk, k + r);
							maxr = max(maxr, r + 1); 
                            break;
                        case 'A':
                            dp[i + 1][j][k + r][r]  = 1;
                            maxk = max(maxk, k + r);
                            break;
                        case 'B':
                            dp[i + 1][j][k][r] = 1;
                            
                            break;
                        case 'C':
                            dp[i + 1][j + k][k][r] = 1;
                            maxj = max(maxj, j + k);
                            break;
                        case 'N':
                            dp[i + 1][j][k][r + 1]  = 1;
                            maxr = max(maxr, r + 1);
                            break;
                    }
                    // 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 = " ";
    short nowi = -1, nowj = -1, nowk = -1;
    for (short j = 0; j <= 400; j++)
    {
        for (short k = 0; k <= 40; k++)
        {
            if (dp[n][kk][j][k])
            {
            cout << j <<" " << k << endl;
                nowi = kk, nowj = j, nowk = k;
                break;
            }
        }
        if (nowi != -1)
            break;
    }
    if (nowi == -1)
    {
        cout << "-1" << endl;
        return;
    }
    // cout << s << endl;
    for (short 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 (short i = n; i >= 1; i--) {
        res.push_back(ans[i]);
    }
    for (short i = 1; i <= n; i++) {
        if (ss[i] != '?')
            res[i - 1] = 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();
    }
}
/*
40 2500
????????????????????????????????????????
*/ 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 83380kb

input:

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

output:

1 1
NBBACBBBBBCBBBBBBBBBBB

result:

wrong answer illegal char