QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#772803 | #9141. Array Spread | SunsetGlow95 | WA | 12ms | 6256kb | C++14 | 1.8kb | 2024-11-22 21:57:28 | 2024-11-22 21:57:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MXM = 4005;
const int DVS = 998244353;
const int MXL = MXM * MXM;
int T, M, bnd[MXM], xx[MXM], xs;
int slen;
pair<int, int> fs[MXL];
void generate(int a, int b, int c, int d) {
if (b + d > M) return;
generate(a, b, a + c, b + d);
fs[slen++] = make_pair(a + c, b + d);
generate(a + c, b + d, c, d);
}
bool check(int id) {
static long long dis[MXM];
static long long INF = 1e18;
int lb(fs[id].first), rb(fs[id].second);
for (int i(1); i != xs; ++i) dis[i] = INF;
dis[0] = 0;
for (int i(0); i <= xs; ++i) {
bool run(false);
for (int j(0); j != xs - 1; ++j)
if (dis[j] > dis[j + 1]) dis[j] = dis[j + 1], run = true;
for (int j(0); j != M; j += 2) {
int l(bnd[j]), r(bnd[j + 1]);
if (dis[l] > dis[r] - lb) dis[l] = dis[r] - lb, run = true;
if (dis[r] > dis[l] + rb) dis[r] = dis[l] + rb, run = true;
}
if (!run) return true;
}
return false;
}
void exgcd(int a, int b, int& x, int& y) {
if (!b) x = 1, y = 0;
else exgcd(b, a % b, y, x), y -= a / b * x;
}
inline int getinv(int a) {
int x(0), y(0);
exgcd(a, DVS, x, y);
return (x % DVS + DVS) % DVS;
}
int main() {
cin >> T;
while (T--) {
cin >> M >> M, M *= 2;
for (int i(0); i != M; ++i) {
cin >> bnd[i];
if (i % 2 == 0) --bnd[i];
}
copy(bnd, bnd + M, xx);
sort(xx, xx + M);
xs = unique(xx, xx + M) - xx;
for (int i(0); i != M; ++i) bnd[i] = lower_bound(xx, xx + xs, bnd[i]) - xx;
generate(0, 1, 1, 1);
fs[slen++] = make_pair(1, 1);
int L(0), R(slen);
while (R - L > 1) {
int mid((L + R) >> 1);
if (check(mid)) L = mid;
else R = mid;
}
cout << fs[L].second * 1LL * getinv(fs[L].first) % DVS << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
3 3 3 1 3 2 3 1 2 12 6 2 3 5 7 1 9 4 8 1 2 7 11 4 5 3 4 2 3 1 2 4 4 1 1
output:
1 2 499122178
result:
ok 3 number(s): "1 2 499122178"
Test #2:
score: 0
Accepted
time: 5ms
memory: 3676kb
input:
2000 1000000000 1 259923446 367011266 1000000000 1 882434225 971573327 1000000000 1 41585677 470369580 1000000000 1 371902212 947250194 1000000000 1 787209148 924205796 1000000000 1 259074809 960876164 1000000000 1 148079314 188254573 1000000000 1 940091047 948318624 1000000000 1 40636497 743979446 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 2000 numbers
Test #3:
score: 0
Accepted
time: 3ms
memory: 3656kb
input:
1000 1000000000 5 575330909 661595447 708422488 913945134 658050911 930246647 786571892 904549453 851755566 969150871 1000000000 2 198072104 844159589 8876188 644559580 1000000000 2 740802634 976972118 783909534 898449184 1000000000 2 871819537 941611957 465883854 640988372 1000000000 1 99458969 462...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 5904kb
input:
500 1000000000 13 964546318 987364574 367845944 907446075 259314137 890312338 458318546 959971971 353677471 522446336 782931403 845199078 514387878 786979588 532634932 793056892 905393511 960628299 747423889 986373313 796099347 833069525 906969434 971335651 574582540 647534593 1000000000 6 987712893...
output:
3 1 3 1 1 1 1 1 1 3 2 1 1 1 3 1 2 1 1 2 1 3 1 1 1 2 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 3 1 2 1 1 1 1 2 3 1 1 1 1 1 1 1 3 2 1 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 1 4 1 2 1 4 1 3 1 1 1 1 1 2 1 1 4 1 ...
result:
ok 500 numbers
Test #5:
score: 0
Accepted
time: 5ms
memory: 4044kb
input:
250 1000000000 10 844342043 888135880 127033337 726074967 581308029 893912240 414276384 752837267 565680461 863374082 230362895 477723054 210479116 423381051 325072305 427826920 178306222 756423471 376470949 993759748 1000000000 2 468173597 607783582 266359996 863641680 1000000000 7 206599093 941381...
output:
2 1 2 1 3 3 1 1 1 2 1 2 2 1 3 5 2 1 1 1 2 1 2 1 3 1 2 1 3 499122178 1 1 1 1 3 1 1 1 3 3 3 1 4 1 1 1 1 1 1 1 1 5 1 4 2 1 3 1 1 1 2 5 2 1 2 6 2 2 1 2 1 1 1 5 8 2 1 2 1 1 2 2 2 1 1 5 8 3 1 1 1 8 2 6 1 1 4 2 1 1 1 1 2 2 1 2 1 1 1 1 1 1 2 1 2 1 1 4 1 1 3 1 2 3 3 2 5 1 1 1 3 2 1 1 1 3 1 1 2 1 1 1 1 3 1 1 ...
result:
ok 250 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
250 1000000000 4 10495745 465086423 465086424 609997778 396956207 663037010 253873206 396956206 1000000000 33 596279983 655818820 226461062 338625457 407323582 423049163 711408063 778512581 220274357 226461061 702491412 711408062 686978949 688730316 369564474 434159428 778512582 787885602 675683057 ...
output:
1 2 748683266 5 6 453747435 1 10 6 1 499122183 1 4 3 1 3 1 748683266 2 499122179 10 499122178 1 499122179 4 1 7 1 665496238 2 2 2 332748119 249561090 816745381 499122178 2 499122179 5 3 4 17 1 2 2 3 249561092 1 3 924300328 499122179 2 3 332748120 2 7 3 499122187 6 374341634 1 2 332748120 2 2 2 49912...
result:
ok 250 numbers
Test #7:
score: 0
Accepted
time: 12ms
memory: 4420kb
input:
100 1000000000 17 272213590 960979163 970159974 987653658 201788340 556786243 46564706 948945765 786605927 819103747 510930374 747773556 729597186 850647589 412727504 443334406 685627406 773178988 793614323 909668193 830162056 837607472 416766039 753918198 237455713 993045890 848459092 851118478 463...
output:
8 1 1 2 3 3 1 5 1 2 8 2 1 1 3 1 3 6 3 3 2 3 7 2 1 1 3 1 2 1 5 5 2 2 4 2 7 2 1 6 1 2 5 4 5 4 1 1 1 8 6 1 4 4 5 13 1 4 9 4 8 3 8 5 4 7 1 8 1 1 1 9 2 1 6 4 4 3 1 1 1 10 4 6 11 6 6 1 1 4 1 4 2 2 13 5 1 1 5 8
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 9ms
memory: 5872kb
input:
100 1000000000 49 187775019 193881727 145323628 162242601 964365230 971504847 226437670 229819402 46971378 49331905 871327590 883354570 310535966 323031740 904117712 916571909 458902934 484636144 13320536 14923771 571938132 574937141 89751784 102733764 412667720 421251698 908036941 932886651 2663244...
output:
2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 3 1 1 1 1 1 1 3 1 3 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 3 1 1 1 1 3 1 1 1 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 10ms
memory: 6256kb
input:
100 1000000000 33 607773622 612059886 773446566 927093401 216659567 357373353 949986996 960422356 67865304 185683459 748675762 867719748 419805439 434936264 83601801 106508219 584299087 639485780 487166380 588591547 670602250 789210083 877816826 902687951 800334389 834278741 90815648 214176329 53952...
output:
4 1 4 6 3 1 1 7 1 1 3 3 1 4 4 1 2 4 1 5 1 2 2 1 2 9 2 1 2 2 1 2 1 2 4 2 2 1 1 3 2 2 2 1 1 1 1 4 1 1 2 1 1 1 2 1 7 1 1 1 6 2 1 3 6 4 10 1 1 3 5 1 1 10 8 1 3 1 1 2 3 1 1 6 1 2 1 2 3 3 2 4 1 3 2 7 1 1 1 1
result:
ok 100 numbers
Test #10:
score: -100
Wrong Answer
time: 4ms
memory: 4428kb
input:
100 1000000000 27 423127198 447304856 209683651 219301129 831320345 879604518 631502329 814498734 130918283 202258454 434769186 463838309 448295746 500976275 778017547 864887407 60178254 66348236 615735891 725460273 78684718 129678593 219427409 221445385 242513397 378886240 549135209 710348598 24951...
output:
748683266 2 332748119 2 855638018 2 2 2 1 1 499122179 1 630470119 1 873463814 10 3 598946613 499122178 499122179 720954257 24956110 686292996 499122178 6 2 499122180 332748122 665496237 27 17 1 15 5 199648872 6 4 3 1 285212675 2 1 4 2 499122186 698771050 844668300 887328319 332748120 1 2 499122179 4...
result:
wrong answer 67th numbers differ - expected: '806274288', found: '554580199'