QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634997#8237. Sugar Sweet IIcy325WA 0ms3796kbC++201.5kb2024-10-12 18:41:102024-10-12 18:41:10

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

// 快速幂计算 x^y % MOD
ll power_mod(ll x, ll y, ll mod) {
    ll res = 1;
    x %= mod;
    while(y > 0){
        if(y & 1) res = res * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}

struct child{
    ll a;
    ll b;
    ll w;
};

void solve(){
    int n;
    cin >> n;
    vector<child> v(n+1);
    for(int i=1;i<=n;i++) cin >> v[i].a;
    for(int i=1;i<=n;i++) cin >> v[i].b;
    for(int i=1;i<=n;i++) cin >> v[i].w;
    
    // 初始化期望值为初始糖果数量
    vector<long long> expectation(n+1, 0);
    for(int i=1;i<=n;i++) expectation[i] = v[i].a;
    
    // 计算每个事件的贡献
    for(int i=1;i<=n;i++){
        int bi = v[i].b;
        if(v[i].a < v[bi].a){
            // 事件 i 有 50% 的概率触发
            // 期望增量为 w[i] / 2
            // 计算 w[i] * inv(2) % MOD
            ll inv2 = power_mod(2, MOD-2, MOD);
            ll contribution = (v[i].w * inv2) % MOD;
            expectation[i] = (expectation[i] + contribution) % MOD;
        }
        // 如果 a[i] >= a[bi],事件不会触发,无需更新
    }
    
    // 输出结果
    for(int i=1;i<=n;i++){
        cout << expectation[i] << (i==n ? '\n' : ' ');
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

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

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:

2 5 5 4
5 7 6
5 4 500000008
2 500000006 3 3 3

result:

wrong answer 1st numbers differ - expected: '500000007', found: '2'