QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687317#8237. Sugar Sweet IIxxk2006WA 56ms15704kbC++232.1kb2024-10-29 18:16:562024-10-29 18:16:56

Judging History

This is the latest submission verdict.

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-29 18:16:56]
  • Judged
  • Verdict: WA
  • Time: 56ms
  • Memory: 15704kb
  • [2024-10-29 18:16:56]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
const int p=1e9+7;
const int N=5e5+9;
LL nf[500009],ans[N];
vector<int> g[500009],f;
int a[N],b[N],c[N];
void dfs(int u,int d){
    cout<<u<<':'<<d<<endl;
    ans[u]=(ans[u]+c[u]*nf[d])%p;
    for(int i=0;i<g[u].size();i++){
        dfs(g[u][i],d+1);
    }
}
LL qpow(LL x,int y){
    LL re=1;
    while(y){
        if(y&1){
            re=re*x%p;
        }
        y>>=1;
        x=x*x%p;
    }
    return re;
}
int main(){
    int T;
    nf[1] = 1;
    for (int i = 2; i <= 500000; ++i) {
        nf[i]=nf[i-1]*i%p;
    }
    for(int i=2;i<=500000;i++){
        nf[i]=qpow(nf[i],p-2);
    }
    read(T);
    while(T--){
        int n;
        read(n);
        f.clear();
        for(int i=1;i<=n;i++)read(a[i]);
        for(int i=1;i<=n;i++)read(b[i]);
        for(int i=1;i<=n;i++)read(c[i]);
        for(int i=1;i<=n;i++){
            if(a[i]<a[b[i]]){
                f.pb(i);
                ans[i]=(a[i]+c[i])%p;
                continue;
            }
            if(a[i]>=a[b[i]]+c[b[i]]){
                ans[i]=a[i];
                continue;
            }
            g[b[i]].pb(i);
            ans[i]=a[i];
        }
        for(int i=0;i<f.size();i++){
            for(int j=0;j<g[f[i]].size();j++){
                dfs(g[f[i]][j],2);
            }
        }
        for(int i=1;i<=n;i++){
            print(ans[i]),spc;
            g[i].clear();
        }
        Enter;
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 56ms
memory: 15704kb

input:

4
4
2 5 5 2
4 2 1 3
3 2 1 4
3
5 4 3
1 1 1
6 6 6
3
5 4 3
2 3 1
1 2 3
5
2 1 3 2 1
5 1 1 3 4
1 3 4 2 4

output:

1:2
500000007 5 5 6 
5 10 9 
2:2
1:3
166666673 5 6 
1:2
500000006 4 3 4 5 

result:

wrong output format Expected integer, but "1:2" found