QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122627#4406. 独立集问题ezoilearner0 67ms56004kbC++141.8kb2023-07-10 20:44:432023-07-10 20:44:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 20:44:44]
  • 评测
  • 测评结果:0
  • 用时:67ms
  • 内存:56004kb
  • [2023-07-10 20:44:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second
const ll inf=1e18;

inline void rd(int &x){
    x=0;char ch=getchar();int f=1;
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    x*=f;
}
//是否解决 系数 类型

int n;
#define Maxn 400010
int a[Maxn];
ll F[Maxn][8];
int head[Maxn],v[Maxn],nxt[Maxn],tot=0;
void add_edge(int s,int e){
    tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
}

int calc(int a,int b){
    int a1=(a/2)&1,a2=a/4;
    int b1=(b/2)&1,b2=b/4;
    if(a2==1&&b2==1)return -1;
    if(a2==0&&b2==0)return 0;
    if(a2==0&&b2==1&&a1!=b1)return 1;
    if(a2==1&&b2==0&&a1!=b1)return 2;
    return 0;
}

ll fjz[8];
void dfs(int u){
    rep(i,0,7)
    if(i!=1&&i!=3){
        int t=(i/2)&1;
        if(t==0)F[u][i]=a[u];
        else F[u][i]=-a[u];
    }else F[u][i]=-inf;
    for(int i=head[u];i;i=nxt[i]){
        int t=v[i];
        dfs(t);
        rep(j,0,7)fjz[j]=-inf;
        rep(c1,0,7)
            rep(c2,0,7){
                int cur=calc(c1,c2);
                if(cur==-1)continue;
                int ss=c2&1;
                if(cur==2)ss=1;
                if(ss==0)continue;
                if(cur==1)c1|=1;
                fjz[c1]=max(fjz[c1],F[u][c1]+F[t][c2]);
            }
        rep(j,0,7)F[u][j]=fjz[j];
    }
}

int main(){
    rd(n);
    rep(i,1,n)rd(a[i]);
    rep(i,2,n){
        int x;rd(x);add_edge(x,i);
    }
    dfs(1);ll Ans=-inf;
    dfs(1);
    rep(i,4,7)Ans=max(Ans,F[1][i]);
    printf("%lld\n",Ans);
    return 0;
}  

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 64ms
memory: 56004kb

input:

351493
-641495974 -401868912 -864400429 35718599 -579296290 767835327 149511992 -246228754 649472235 893048442 -292675192 -788090312 -578172296 -62289673 196890164 -120059197 -452848333 -216788131 -604555771 -240241020 376984486 -407661514 -107574590 -461679558 -470560314 -583391402 -991686079 76956...

output:

-999999999358504026

result:

wrong answer 1st numbers differ - expected: '175477002777567', found: '-999999999358504026'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 67ms
memory: 33068kb

input:

351493
915594742 688454502 456077914 208864399 625937959 102483811 538999077 529481828 400375958 387560315 83710527 83424975 330114353 684812426 68052931 28849220 295907801 535129167 967891325 124069427 644256858 757666812 558755455 178666038 177054898 795236216 848264282 669310447 328353372 3681163...

output:

-1000000000000000000

result:

wrong answer 1st numbers differ - expected: '175766699890054', found: '-1000000000000000000'

Subtask #3:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 1ms
memory: 5620kb

input:

7
247522519 398923496 -976223527 806215585 -937536479 -130552271 90576461
1 2 1 2 5 5

output:

-916167634

result:

wrong answer 1st numbers differ - expected: '3587550338', found: '-916167634'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%