QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580916#9376. GameSFproWA 407ms3712kbC++202.5kb2024-09-22 00:57:062024-09-22 00:57:06

Judging History

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

  • [2024-09-22 00:57:06]
  • 评测
  • 测评结果:WA
  • 用时:407ms
  • 内存:3712kb
  • [2024-09-22 00:57:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int MOD = 998244353;
int power(int a, int  b, int p) {// a^ b % p
    int res = 1;
    for (; b; b /= 2, a =  a * a % p) {
        if (b % 2 == 1) {
            res =  res * a % p;
        }
    }
    return res;
}
void read() {
    int x, y;
    cin >> x >> y;
    int a0, a1, b;
    cin >> a0 >> a1 >> b;
    int ans = 0, res = a0 % MOD * power(a1 + a0, MOD - 2, MOD) % MOD; //res:单回合获胜的概率
    if(x == y) {
        ans = a0 % MOD * power(a1 + a0, MOD - 2, MOD) % MOD;
        cout << ans << endl;
    } else {
        int num1 = 0, num2 = 0, i = 0, temp = 1; //temp:到目前情况的概率
        if(x > y) ans = res;
        while(y != 0 && x != 0 && y != x) {
            if(y >= x) {//y>=x时,只许胜不许败
                num1 = y % x == 0 ? y / x - 1 : y / x;
                y %= x;
//                int q = (power(a0 + a1, num1, MOD) - a0 * power(a0 + a1, num1 - 1, MOD) + MOD) % MOD;//等比数列求和的分母
//                q = power(q, MOD - 2, MOD);//逆元
//                int u = (power(a0 + a1, num1, MOD) - power(a0, num1, MOD) + MOD) % MOD;//1-q的num1次方
//                ans += res * temp % MOD * a0 % MOD * power(a0 + a1, num1 - 1, MOD) % MOD  * u % MOD * q % MOD;
                temp = temp * power(a0, num1, MOD) % MOD * power(power(a0 + a1, num1, MOD), MOD - 2, MOD) % MOD;
                temp %= MOD;
                ans += res * temp % MOD;
            } else {//可败,败了影响概率,等比数列求和
                num2 = x % y == 0 ? x / y - 1 : x / y;
                x %= y;
                //cout<<temp<<" "<<num2<<endl;
                int q = (power(a0 + a1, num2 + 1, MOD) - a1 * power(a0 + a1, num2, MOD) % MOD + MOD) % MOD; //分母
                q = power(q, MOD - 2, MOD);//逆元
                int u = (power(a0 + a1, num2, MOD) % MOD - power(a1, num2, MOD) % MOD + MOD) % MOD;
                ans += res * temp % MOD * a1 % MOD * u % MOD * q % MOD;
                temp = temp * power(a1, num2, MOD) % MOD * power(power(a0 + a1, num2, MOD), MOD - 2, MOD) % MOD;
                temp %= MOD;
            }
            ans %= MOD;
        }
        cout << ans << endl;
//       cout<<(7*power(10,MOD-2,MOD)%MOD)<<endl;
    }
}
signed main() {
    ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) {
        read();
    }
    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

output:

499122177
910398850
220911476

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 79ms
memory: 3712kb

input:

100000
1 1000000000
12980050 128257807 266126484
1 1000000000
400255084 123438563 768881284
1000000000 1000000000
24563487 72082135 450057094
1 1000000000
56952077 40876000 193815114
1000000000 1000000000
82048274 239365585 326520865
1000000000 1
309821265 346013425 963168258
1 1
104158269 199365020...

output:

947058399
376449942
612621163
138416357
592200562
45779380
870227707
169499045
86396463
415694940
46851356
951368934
426243016
864656779
750317399
922456360
486881524
824329239
198191519
189360084
966510181
512645443
695650039
703100783
550002158
438470182
246877045
39876086
667870434
405196653
5935...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 407ms
memory: 3652kb

input:

100000
167959139 481199252
18199423 25950409 149762920
773386884 579721198
16629525 28339910 152155823
2087506 268792718
43528658 6471925 90197530
691952768 717268783
516613092 94328992 743662288
45277106 856168102
309821265 346013425 963168258
279198849 527268921
30167950 166388455 577970339
140515...

output:

111307212
952164090
776159793
686215457
349269124
374842963
412084092
79533762
286086009
778147923
155440529
688610964
882386961
953649977
109612740
382211901
900328335
520308570
714433628
161607199
973307502
992272281
796334630
734390111
743921125
574889610
805293646
336501070
475912248
45683411
59...

result:

wrong answer 1st lines differ - expected: '623291477', found: '111307212'