QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714671#8237. Sugar Sweet IIKopicyWA 6ms11416kbC++232.0kb2024-11-06 02:13:102024-11-06 02:13:10

Judging History

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

  • [2024-11-06 02:13:10]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:11416kb
  • [2024-11-06 02:13:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define drep(i, a, b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)x.size()
#define endl "\n"
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18;

int fac[N];
int qpow(int a,int b){
    int res=1;a%=mod;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int inv(int x){return qpow(x,mod-2);}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), w(n + 1);
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n) cin >> b[i];
    rep(i, 1, n) cin >> w[i];

    vector<int> must(n + 1);
    vector<vector<int>> g(n + 1);
    rep(i, 1, n) {
        if(b[i]==i){
            must[i]=-1;
            continue;
        }
        if (a[i] < a[b[i]]) {
            must[i] = 1;
        }
        else if (a[i] >= a[b[i]]+w[b[i]]){
            must[i]=-1;
        }
        else{
            g[b[i]].push_back(i);
        }
    }
    vector<int> to(n+1);
    rep(i,1,n){
        if(must[i]==1){
            to[i]=1;
            function<void(int,int)> dfs=[&](int u,int pro){
                for(int v:g[u]){
                    to[v]=to[u]*(pro+1)%mod;
                    dfs(v,pro+1);
                }
            };
            dfs(i,1);
        }
        else if(must[i]==-1){
            function<void(int)> dfs=[&](int u){
                for(int v:g[u]){
                    if(must[v]) continue;
                    must[v]=-1;
                    dfs(v);
                }
            };
            dfs(i);
        }
    }
    rep(i,1,n){
        if(must[i]==-1) cout<<a[i]<<" ";
        else cout<<(a[i]+w[i]*inv(fac[to[i]])%mod)%mod<<" ";
    }
    cout<<endl;
}

signed main() {
    IOS
    fac[0]=1;
    rep(i,1,N-1) fac[i]=fac[i-1]*i%mod;
    int64_t tt = 1;
    cin >> tt;
    rep(kase, 1, tt) solve();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 11416kb

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 
301388896 5 6 
500000006 4 3 4 5 

result:

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