/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 772.0 KiB
#2 Wrong Answer 2ms 840.0 KiB
#3 Wrong Answer 2ms 2.531 MiB

Code

#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 30,inf = 1e5;
int n,a[N],dp[N][N][N][N],diff;

int yo(int i,int start,int mxp,int mnp) {
    if(i == n) {
        if(mxp == n) return 0;
        return (a[mxp] - a[mnp] == diff)? 0 : -inf;
    }
    auto &ret = dp[i][start][mxp][mnp];
    if(~ret) return ret;
    int nmxp = mxp,nmnp = mnp;
    if(i + 1 < n and a[i+1] > a[mxp]) nmxp = i+1;
    if(i + 1 < n and a[i+1] < a[mnp]) nmnp = i+1;
    ret = yo(i+1,start,nmxp,nmnp);
    if(start != i and a[mxp] - a[mnp] == diff) 
        ret = max(ret, 1 + yo(i + 1, i + 1, i + 1, i + 1));
    return ret;
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                for(int l = 0; l < n; l++) {
                    dp[i][j][k][l] = -1;
                }
            }
        }
    }
    sort(a,a+n);
    int ans = 0;
    for(int i = 1; i < n; i++) {
        int mx = 0,mn = INT_MAX;
        for(int j = 0; j <= i; j++) {
            mx = max(mx, a[j]);
            mn = min(mn, a[j]);
        }
        diff = mx - mn;
        ans = max(ans, yo(i+1,i+1,i+1,i+1) + 1);
    }
    cout << ans << '\n';
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1162 Roy and Maximum Partition
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 16:39:29
Judged At
2025-02-17 16:39:29
Judged By
Score
0
Total Time
2ms
Peak Memory
2.531 MiB