QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#460779 | #7408. Determination | Kazemaru | WA | 3ms | 50444kb | C++14 | 1.3kb | 2024-07-02 09:11:56 | 2024-07-02 09:11:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
const int N=2e6,mo=1e9+7;
inline int read(){
int x=0,f=1;char ch=getchar();
for(;'0'>ch||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
return x*f;
}
#define rd()(read()+mo-X)%mo
int a[N],b[N],c[N],d[N],f[N][6],X;
vector<int>q[N];
#define fd(x) dfs(x);int p=(f[x][0]*a[x]+f[x][1])%mo,q=(f[x][2]*a[x]+f[x][3])%mo
void dfs(int x){
f[x][0]=1;
for(int y:q[x]){
fd(y);
f[x][3]=(f[x][1]*q+f[x][3]*p+f[x][2]*f[y][0]%mo*d[y]+f[x][0]*f[y][2]%mo*d[y]+f[x][4]*f[y][5]+f[x][5]*f[y][4])%mo;
f[x][4]=(f[x][0]*f[y][4]+f[x][4]*p)%mo;f[x][5]=(f[x][0]*f[y][5]+f[x][5]*p)%mo;
f[x][1]=(f[x][1]*p+f[x][0]*f[y][0]%mo*d[y])%mo;f[x][2]=(f[x][2]*p+f[x][0]*q)%mo;f[x][0]=f[x][0]*p%mo;
}
f[x][3]=(f[x][0]+f[x][3]+f[x][4]+f[x][5])%mo;
f[x][4]=(f[x][0]+f[x][4])*b[x]%mo;
f[x][5]=(f[x][0]+f[x][5])*c[x]%mo;
}
signed main(){
cin>>n>>X;
f(i,1,n)a[i]=mo-rd();
f(i,2,n){
q[read()].push_back(i);
b[i]=rd();c[i]=rd();
d[i]=mo-b[i]*c[i]%mo;
}
fd(1);cout<<(p-q*X%mo+mo)*(n%2?mo-1:1)%mo;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 50444kb
input:
3 1 23333 233 3 1 1 1 1 1 2 3 1 4 5 3 1 2 3 4 1 4 5 2 6 7
output:
16285968
result:
wrong answer 1st numbers differ - expected: '233', found: '16285968'