比赛 省选2023Day2复现 评测结果 AAWWWWWWWWWWWWWWWWWW
题目名称 染色数组 最终得分 10
用户昵称 flyfree 运行时间 0.056 s
代码语言 C++ 内存使用 3.83 MiB
提交时间 2025-12-13 12:18:25
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
// #define LOCAL
#define ll long long
#define db double
#define Ciallo true
#define pir pair <ll,ll>
#define fs first
#define sc second
#define MAXN 60
#define mod 998244353
#define add(x, y) x = (x + y) % mod
#define chkmax(x, y) x = max(x, y)
inline ll read(){
    ll f = 1, num = 0;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c=='-') f = -1;c = getchar();
    }
    while(c>='0'&&c<='9') num = num * 10 + c - '0', c = getchar();
    return num * f;
}

int a[MAXN];
int n,m,t;
ll f[MAXN][MAXN],g[MAXN][MAXN];
ll sr[MAXN],sg[MAXN];

void solve1(){
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    memset(sr, 0, sizeof(sr));
    memset(sg, 0, sizeof(sg));
    for(int i = 1;i <= n; ++i){
        for(int j = 1;j < i; ++j){
            if(a[j] > a[i])sr[i] += m - a[i] + 1;
            if(a[j] < a[i])sg[i] += a[i];
        }
    }

    f[0][0] = 1, g[0][0] = 0;

    for(int i = 0;i < n; ++i){
        for(int j = 0;j < n; ++j){
            if(!f[i][j])continue;
            if(i <= j){ // 扩展红色
                int res = a[i];
                ll coef = 0;
                for(int k = j + 1;k <= n; ++k){
                    if(a[k] <= res)break;
                    res = a[k];
                    add(coef, sr[k]);
                    add(f[k][j], f[i][j]);
                    chkmax(g[k][j], g[i][j] + coef);
                }
            }
            if(j <= i){// 扩展绿色
                int res = (j == 0 ? 1e9 : a[j]);
                ll coef = 0;
                for(int k = i + 1;k <= n; ++k){
                    if(a[k] >= res)break;
                    res = a[k];
                    add(coef, sg[k]);
                    add(f[i][k], f[i][j]);
                    chkmax(g[i][k], g[i][j] + coef);
                }
            }
        }
    }
    cerr << "done dp\n";

    ll cnt = 0, ans = 0;
    for(int j = 0;j < n; ++j){
        add(cnt, f[n][j]);
        chkmax(ans, g[n][j]);
    }
    for(int i = 0;i < n; ++i){
        add(cnt, f[i][n]);
        chkmax(ans, g[i][n]);
    }
    // for(int i = 0;i <= n; ++i){
    //     for(int j = 0;j <= n; ++j){
    //         cerr << f[i][j] << " ";
    //     }
    //     cerr << endl;
    // }
    if(cnt >= 2){
        cout << 1 << " " << ans << endl;
    }else{
        cout << 0 << " " << 0 << endl;
    }
}

void work(){
    n = read(),m = read(), t = read();
    for(int i = 1;i <= t; ++i){
        a[i] = read();
    }
    if(t == n)solve1();
    else{
        cout << "I can't solve it now\n";
        return;
    }
    // cerr << n << " " << m << " " << t << endl;
}

int main(int argc, char* argv[]){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    #ifdef FS
        freopen(argv[1], "r", stdin);
        freopen(argv[2], "w", stdout);
    #elif defined(LOCAL)
        freopen("w.in", "r", stdin);
        freopen("w.out", "w", stdout);
    #endif

    int T = read();
    while(T --)work();

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s \n";
    return 0;
}