QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#197832#6955. AssignmentPPP#WA 278ms5016kbC++173.4kb2023-10-02 20:28:522023-10-02 20:28:53

Judging History

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

  • [2023-10-02 20:28:53]
  • 评测
  • 测评结果:WA
  • 用时:278ms
  • 内存:5016kb
  • [2023-10-02 20:28:52]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, k;
const int maxN = 105;
int a[maxN], b[maxN];
const int maxK = 11;
int dp[maxN][maxN][maxK];
const int INF = 1e9;
int A[maxN][maxN];
int help[maxN][maxN][maxK];
int suf_help[maxN][maxN][maxK];
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            for (int t = 0; t <= k; t++) {
                dp[i][j][t] = INF;
                suf_help[i][j][t] = INF;
                help[i][j][t] = INF;
                if (i > j) dp[i][j][t] = 0;
            }
        }
    }
    for (int l = n; l >= 1; l--) {
        for (int r = l; r <= n; r++) {
            int cnt = 0;
            for (int p = l; p <= r; p++) {
                if (a[p] != b[p]) cnt++;
            }
            if (l == r) {
                for (int c = 0; c <= k; c++) {
                    if (a[l] == b[l]) {
                        dp[l][r][c] = help[l][r][c] = suf_help[l][r][c] = 0;
                    }
                    else {
                        dp[l][r][c] = (c == 0 ? A[b[l]][1] : 0);
                        help[l][r][c] = 0;
                        suf_help[l][r][c] = A[b[l]][1];
                    }
                }
                continue;
            }

            for (int mid = l; mid < r; mid++) {
                for (int was = 0; was <= k; was++) {
                    for (int will = 0; will + was <= k; will++) {
                        if (was + will + (b[r] != b[l]) <= k) {
                            int nxt = was + will + (b[r] != b[l]);
                            help[l][r][nxt] = min(help[l][r][nxt],
                                                         help[l][mid][was] + dp[mid + 1][r - 1][will]);
                        }
                    }
                }
            }


            for (int mid = l; mid <= r; mid++) {
                for (int was = 0; was <= k; was++) {
                    for (int will = 0; will + was <= k; will++) {
                        suf_help[l][r][was + will] = min(suf_help[l][r][was + will],
                                                         help[l][mid][was] + A[b[l]][mid - l + 1] + dp[mid + 1][r][will]);

                    }
                }
            }
            for (int D = 0; D <= k; D++) {
                if (D >= cnt) dp[l][r][D] = 0;
            }
            for (int mid = l; mid <= r; mid++) {
                for (int was = 0; was <= k; was++) {
                    for (int will = 0; will + was <= k; will++) {
                        dp[l][r][was + will] = min(dp[l][r][was + will],
                                                         suf_help[mid][r][was] + dp[l][mid - 1][will]);

                    }
                }
            }
        }
    }
    for (int i = 0; i <= k; i++) {
        cout << dp[1][n][i] << " ";
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 278ms
memory: 5016kb

input:

10
100 10
24 56 71 49 70 39 19 23 96 26 85 33 73 84 35 75 58 77 85 40 33 36 75 55 7 28 37 7 100 94 35 64 68 46 77 80 90 28 85 8 9 23 32 45 4 51 47 82 6 49 45 55 28 69 80 7 61 41 83 42 16 25 82 56 26 92 14 66 43 1 2 62 25 84 19 58 35 37 14 61 38 12 27 95 98 100 61 36 75 83 35 19 74 56 87 10 10 6 60 5...

output:

27473279 26539877 25650181 24801901 24025447 23252605 22479763 21733001 20960159 20221324 19493165 
30992495 30067022 29194972 28394080 27612070 26867897 26124539 25400737 24745946 24091155 23436364 
3973096 3343250 2761180 2428393 2215777 2075964 1991108 1914392 1829536 1823074 1749700 
5341649 453...

result:

wrong answer 2nd lines differ - expected: '32063854 31138381 30266331 294...4311 25690509 25035718 24380927', found: '30992495 30067022 29194972 283...737 24745946 24091155 23436364 '