UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215144#2686. Oversleepingwanghanyu39310210ms1196kbC++111008b2024-11-26 20:12:102024-11-26 23:03:55

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

int minn = 0x7f7f7f7f7f7f7f7f;

int exgcd(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(b, a % b, y, x);
    y -= (a / b) * x;
    return d;
}

void solve(){
    int x, y, p, q;
    cin >> x >> y >> p >> q;
    minn = 0x7f7f7f7f7f7f7f7f;
    int a, b;
    bool flag = 0;
    int d = exgcd(2 * (x + y), p + q, a, b);
    for(int i = p - (x + y - 1); i <= p + q - 1 - x; i++){
        if(i % d != 0) continue;
        flag = 1;
        int k = i / d;
        int aa = a * k;
        aa = ((aa % (p + q) / d) + ((p + q) / d)) % ((p + q) / d);
        if(i >= p - x) minn = min(minn, aa * 2 * (x + y) + x);
        else minn = min(minn, aa * 2 * (x + y) + p - i);
    }
    if(!flag) cout << -1 << '\n';
    else cout << minn << '\n';
}

signed main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

10
42 337 468 315
179 261 297 332
336 189 230 33
240 398 38 204
465 158 454 462
112 184 90 263
320 4...

output:

1558
297
493
240
465
112
475
46
386
268

result:

wrong answer 8th lines differ - expected: '187', found: '46'

Test #2:

score: 5
Accepted
time: 1ms
memory: 1192kb

input:

10
96 471 276 491
226 87 207 365
451 201 191 173
46 375 100 8
39 179 214 269
135 260 91 431
253 288 ...

output:

276
226
555
100
214
135
458
374
378
99

result:

ok 10 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 1196kb

input:

10
337 285 340 338
484 25 321 156
246 482 122 234
229 441 426 72
6 93 155 338
21 317 406 335
160 298...

output:

340
5574
246
426
204
697
372
469
437
492

result:

ok 10 lines

Test #4:

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

input:

10
196 433 313 366
262 415 94 30
353 22 242 460
283 172 13 276
56 247 344 4
297 363 415 479
473 26 6...

output:

313
342
353
283
266
415
473
169
71
176

result:

wrong answer 5th lines differ - expected: '692', found: '266'

Test #5:

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

input:

10
437 267 140 198
383 155 226 424
273 308 151 317
15 231 435 285
404 294 253 64
109 199 388 147
425...

output:

478
383
273
15
570
923
427
467
328
123

result:

wrong answer 4th lines differ - expected: '507', found: '15'

Test #6:

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

input:

10
21 426 135 234
111 51 109 11
185 42 230 22
472 346 269 285
77 128 499 461
173 79 230 382
102 127 ...

output:

21
111
2496
472
14427
173
207
290
268
141

result:

wrong answer 1st lines differ - expected: '135', found: '21'

Test #7:

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

input:

10
790950658 153 395731486 328
228237805 89 805489534 371
733742769 407 150980036 116
210282811 256 ...

output:

246891340899488
219450506843017
256581917471857
481464741052336
796930710535294
544025599745527
1427...

result:

wrong answer 1st lines differ - expected: '493783472749894', found: '246891340899488'

Test #8:

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

input:

10
935151576 163 823994136 316
552819682 244 661178089 95
751586616 375 326537181 182
9424664 344 31...

output:

1743570779178818
1803106770097497
309929672717638
1902164539224
758138016952709
58456733062296
46884...

result:

wrong answer 1st lines differ - expected: '3487138752902582', found: '1743570779178818'

Test #9:

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

input:

10
480628854 293 138727635 133
188840646 190 569211831 53
442713615 341 668626439 341
527553711 268 ...

output:

118700499805150
169506744687647
851700634689751
28082225856120
42641558939730846
3301500931532
43987...

result:

wrong answer 1st lines differ - expected: '237399557723152', found: '118700499805150'

Test #10:

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

input:

10
128375946 395 45119743 26
591869966 93 644623523 312
553967887 448 714110036 391
129391856 52 673...

output:

173096624515978
4605051504620056
259872639599737
14331835905752
51307973493588
961565343460272
29436...

result:

wrong answer 5th lines differ - expected: '256533712389188', found: '51307973493588'

Test #11:

score: 0
Wrong Answer
time: 1ms
memory: 1196kb

input:

10
416394745 108 799849287 309
285823581 120 50495267 151
984269713 448 325585187 230
502469917 398 ...

output:

143442613725303
1122206445516503
781934728273229
174058229467371
1211468850327338
1055214244538613
1...

result:

wrong answer 1st lines differ - expected: '510932724030159', found: '143442613725303'

Test #12:

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

input:

10
858503120 86 550141525 344
266071218 423 114926419 32
463189501 184 235629038 219
681438792 48 66...

output:

1864662953909472
4760287728949
108859302958239
498732139658022
348331947701166
299409242240879
33631...

result:

wrong answer 2nd lines differ - expected: '14279266757365', found: '4760287728949'

Test #13:

score: 0
Wrong Answer
time: 1ms
memory: 1196kb

input:

10
49615553 235 484012586 439
733063300 215 529603390 181
217670208 264 477723402 451
412727927 119 ...

output:

54608674362107
108602626683520
183965723103840
270657559821653
2759901162755344
200969878188150
1213...

result:

wrong answer 1st lines differ - expected: '163825824623411', found: '54608674362107'

Test #14:

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

input:

10
411060288 247 193494425 14
162692451 151 282497312 400
796796095 370 100991720 365
560074247 197 ...

output:

236839515269254
120719374917267
86736872790465
638082172634567
238702071887920
225997341123648
14196...

result:

wrong answer 2nd lines differ - expected: '56984873468971', found: '120719374917267'

Test #15:

score: 0
Wrong Answer
time: 31ms
memory: 1196kb

input:

10
733526255 46680 232614188 25143
740109721 35101 664765419 65813
926232187 19192 248710599 18813
7...

output:

483424517485
10652904387945
5191638972101
2943858989748
1006825631184
685064834622
84805986649153
16...

result:

wrong answer 2nd lines differ - expected: '2802928408299', found: '10652904387945'

Test #16:

score: 0
Wrong Answer
time: 33ms
memory: 1192kb

input:

10
40397805 9224 854461643 50758
463970290 6807 993317097 75888
496579182 67022 428873070 56575
8340...

output:

2384944063443
7726610589534
4885508641726
611360282515
6103014773068
8282538430184
556922158601
3762...

result:

wrong answer 4th lines differ - expected: '3458814687913', found: '611360282515'

Test #17:

score: 0
Wrong Answer
time: 23ms
memory: 1192kb

input:

10
677231818 45638 135553472 57886
334073954 74682 504512612 32658
528899984 14506 658263816 15374
1...

output:

1964781897104
3957990518738
3334805844944
154674610748
4250858104139
463257371569
131011350948
18109...

result:

wrong answer 1st lines differ - expected: '11785305009104', found: '1964781897104'

Test #18:

score: 0
Wrong Answer
time: 42ms
memory: 1192kb

input:

10
591761203 22205 53945697 65976
829627579 78277 112598137 27980
144133461 55044 668263637 96424
30...

output:

92909972851
2908118947003
97038821414
1533942829336
3950791693215
8266974861556
111818018746
1873146...

result:

wrong answer 1st lines differ - expected: '408922312723', found: '92909972851'

Test #19:

score: 0
Wrong Answer
time: 43ms
memory: 1196kb

input:

10
798158737 58985 625637387 56023
950567276 86709 613154552 23440
2676550 96868 636525260 84971
205...

output:

3886522076243
5431086186536
23554542206
24272607792265
1962460002814
1290940900229
2072034369988
293...

result:

wrong answer 1st lines differ - expected: '1279542967427', found: '3886522076243'

Test #20:

score: 0
Wrong Answer
time: 35ms
memory: 1192kb

input:

10
76769987 47758 832950079 87350
226318103 39942 857729326 28604
700759579 85249 4088534 87174
7300...

output:

622607817508
2308172952526
51161625762
63299765465801
51630285116816159
9900452209294
81419373006
20...

result:

wrong answer 1st lines differ - expected: '845532903085', found: '622607817508'