QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32221#2571. Aidana and PitaRobeZH#WA 110ms12488kbC++1.4kb2022-05-18 06:00:482022-05-18 06:00:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 06:00:50]
  • 评测
  • 测评结果:WA
  • 用时:110ms
  • 内存:12488kb
  • [2022-05-18 06:00:48]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define st first
#define nd second
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int N=30;
int a[N],n;
int dp[1<<25],to[1<<25],sum=0;
int ot[N];
int main() {
    //scanf("%d",&n);
    n=20;
    rep(i,n){
        //scanf("%d",a+i);
        a[i]=i*i;
        sum+=a[i];
    }
    for(int mk=1;mk<1<<n;++mk){
        dp[mk]=sum;
        for(int j=0;j<n;++j)if(mk&(1<<j)){
            int now=dp[mk-(1<<j)];
            if(now<0)now+=a[j+1];else now-=a[j+1];
            if(abs(now)<abs(dp[mk])){
                dp[mk]=now;
                to[mk]=j;
            }
        }
    }
    int ans=sum+1,is=0;
    for(int mk=0;mk<1<<n;++mk){
        int s=0;
        for(int j=0;j<n;++j)if(mk&(1<<j))
            s+=a[j+1];
        int u=s,v=(sum-s-dp[(1<<n)-1-mk])/2,w=(sum-s+dp[(1<<n)-1-mk])/2;
        int nw=max(abs(u-v),max(abs(v-w),abs(w-u)));
        if(ans>nw){
            ans=nw;
            is=(1<<n)-1-mk;
        }
    }
    for(int j=0;j<n;++j)if(!(is&(1<<j)))ot[j+1]=3;
    while(is>0){
        int nxt=is-(1<<to[is]);
        ot[to[is]+1]=(dp[nxt]<0?1:2);
        is=nxt;
    }
    //printf("%d\n",ans);
    rep(i,n)printf("%d%c",ot[i]," \n"[i==n]);
    return 0;
}
/*
20
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
 */

详细

Test #1:

score: 0
Wrong Answer
time: 110ms
memory: 12488kb

input:

5
2 3 1 4 2

output:

2 3 2 1 2 2 3 3 3 3 3 3 3 2 3 1 2 1 1 2

result:

wrong answer expected 0, found 2