QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#323927#8237. Sugar Sweet IIucup-team2279#WA 0ms3524kbC++14855b2024-02-10 14:20:092024-02-10 14:20:09

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-02-10 14:20:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2024-02-10 14:20:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int inv(int x){
	int res=1,y=mod-2;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod;
	return res;
}
void solve(){
	int n;
	cin>>n;
	vector<int> a(n),b(n),w(n),f(n),d(n),vis(n);
	for(int&x:a) cin>>x;
	for(int&x:b) cin>>x,x--;
	for(int&x:w) cin>>x;
	for(int i=0;i<n;i++){
		int x=b[i];
		if(a[x]+w[x]<=a[i]) f[i]=1;
		if(a[x]>a[i]) f[i]=2;
	}
	auto calc=[&](auto self,int x)->void{
		if(f[x]||d[x]) return;
		if(vis[x]) {f[x]=1;return;}
		vis[x]=1;
		self(self,b[x]);
		vis[x]=0;
		if(f[b[x]]==1) f[x]=1;
		else d[x]=d[b[x]]+1;
	};
	for(int i=0;i<n;i++){
		calc(calc,i);
		cout<<(a[i]+(f[i]!=1?1ll*w[i]*inv(d[i]+1):0))%mod<<" ";
	}
	cout<<"\n";
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

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:

500000007 5 5 6 
5 10 9 
333333341 5 6 
500000006 4 3 4 5 

result:

wrong answer 8th numbers differ - expected: '166666673', found: '333333341'