QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560426 | #8237. Sugar Sweet II | shabi666# | WA | 222ms | 44356kb | C++14 | 1.8kb | 2024-09-12 15:41:50 | 2024-09-12 15:41:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int n,m; int p[N]; int mod=1e9+7;
void init(){
p[0]=1;
for(int i=1;i<N;i++) p[i]=p[i - 1]*i%mod;
}
int qmi(int a,int b){
int res=1;
while(b)
{
if(b & 1) res=res*a%mod;
b>>=1; a=a*a%mod;
}
return res;
}
int inv(int x) {
return qmi(x, mod - 2);
}
vector<int> edges[N];
int d[N];
int ans[N];
int a[N], b[N], w[N];
void solve(){
cin>>n;
for(int i=0;i<=n;i++)
{
edges[i].clear();
d[i]=0;
}
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++) cin>>w[i];
for (int i = 1; i <= n; i++) {
if (a[i] >= a[b[i]] && a[i] < a[b[i]] + w[b[i]]) {
d[i]++;
edges[b[i]].emplace_back(i);
}
if (a[i] >= a[b[i]] + w[b[i]] || b[i] == i) {
d[i] = 1;
ans[i] = a[i];
}
}
queue<int> q;
for (int i = 1; i <= n; i++) {
//cout << d[i] << " ";
if (d[i] == 0) {
q.emplace(i);
}
}
int step = 1;
while (!q.empty()) {
int size = q.size();
for (int i = 1; i <= size; i++) {
int u = q.front(); q.pop();
ans[u] = (a[u] + inv(p[step]) * w[u] % mod) % mod;
for (auto v : edges[u]) {
if (--d[v] == 0) {
q.emplace(v);
}
}
}
step++;
}
for (int i = 1; i <= n; i++) {
if(ans[i])
cout << ans[i] << ' ';
else cout<<a[i]<<' ';
}
cout << endl;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1; cin>>T;
init();
while(T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 44356kb
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 166666673 5 6 500000006 4 3 4 5
result:
ok 15 numbers
Test #2:
score: -100
Wrong Answer
time: 222ms
memory: 34880kb
input:
50000 5 508432375 168140163 892620793 578579275 251380640 3 4 4 1 3 346232959 736203130 186940774 655629320 607743104 1 863886789 1 364158084 18 864679185 463975750 558804051 604216585 694033700 499417132 375390750 337590759 467353355 111206671 983760005 984444619 322277587 138763925 205122047 97736...
output:
854665334 904343293 590444253 906393935 859123744 863886789 871186919 814243920 968784984 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959 871186919 814243920 132646723 421298438 601054667 99438820...
result:
wrong answer 25th numbers differ - expected: '665922935', found: '871186919'