QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608047#9376. GameSatonWA 74ms3604kbC++201.7kb2024-10-03 18:03:422024-10-03 18:03:43

Judging History

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

  • [2024-10-03 18:03:43]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:3604kb
  • [2024-10-03 18:03:42]
  • 提交

answer

///by Saton.
#include<bits/stdc++.h>
#define PI acos(-1)
#define fi first
#define se second 
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define LL long long
#define ll __int128
#define DD double double
#define LD long double
#define rep(i,a,b) for(LL i = (a);i <= (b);i ++)
#define lep(i,a,b) for(LL i = (a);i >= (b);i --)
#define FLUSH fflush(stdout)
using namespace std;
const int N = 2e5 + 10,mod =  998244353,P = 131;
const LL inf = 1e9+10,INF = 1e18+10;
typedef pair<int,int> PII;
typedef pair<LL,int> PLI;
LL qmi(LL a,LL b,LL p) {LL res = 1;while(b) {if(b&1) res = (LL)res*a%p;a = (LL)a*a%p;b >>= 1;}return res%p;}
LL x,y,a0,a1,a,b,p0,p1;
LL ans1,ans2;

void dfs(LL x,LL y,LL p) {
    // cout << x << " " << y << " " << p << '\n';
    if(x==y) {
        ans1 = (ans1 + p0*p%mod) % mod;
        ans2 = (ans2 + p1*p%mod) % mod;
        return;
    }
    else if(x>y) {
        LL t = (x-1)/y;
        LL pr = qmi(p1,t,mod);
        ans1 = (ans1 + p*(1-pr+mod)%mod) % mod;
        x -= y*t;
        p = p*pr%mod;
        dfs(x,y,p);
    }
    else {
        LL t = (y-1)/x;
        LL pr = qmi(p0,t,mod);
        ans2 = (ans2 + p*(1-pr+mod)%mod) % mod;
        y -= x*t;
        p = p*pr%mod;
        dfs(x,y,p);        
    }
}

void solve() {
    cin >> x >> y >> a0 >> a1 >> b;
    a = (a0+a1)%mod;
    p0 = a0*qmi(a,mod-2,mod);
    p1 = a1*qmi(a,mod-2,mod);
    
    ans1 = ans2 = 0;
    dfs(x,y,1);
    
    cout << ans1 << '\n';
} 

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while(T --) { 
        solve();
    }
    // solve();
       
    return 0;
}  
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

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: -100
Wrong Answer
time: 74ms
memory: 3604kb

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:

57660923
-648544371
612621163
-282387315
592200562
76520153
870227707
169499045
667597353
415694940
140987510
-533339125
426243016
864656779
750317399
268631494
486881524
-982223665
198191519
189360084
966510181
512645443
695650039
709706254
550002158
616407070
458326158
-446789067
667870434
9182184...

result:

wrong answer 1st lines differ - expected: '947058399', found: '57660923'