QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275360 | #7256. Number Cards | PetroTarnavskyi# | AC ✓ | 245ms | 74580kb | C++20 | 1.5kb | 2023-12-04 17:19:38 | 2023-12-04 17:19:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int C = 20;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI a(n), c(n), l(C, n), r(C, 0), cnt(C, 0);
vector<VI> vec(n);
FOR(i, 0, n)
{
cin >> a[i] >> c[i];
a[i]--;
c[i]--;
l[c[i]] = min(l[c[i]], i);
r[c[i]] = i;
cnt[c[i]]++;
}
FOR(i, 0, C)
{
if (cnt[i] > 0 && cnt[i] != r[i] - l[i] + 1)
{
cout << "0\n";
return 0;
}
}
FOR(i, 0, n)
{
for (int x = 1; ; x = a[i] / (a[i] / x) + 1)
{
vec[i].PB(x);
if (x > a[i])
break;
}
}
vector<PII> events;
FOR(i, 0, n - 1)
{
VI cur;
cur.resize(SZ(vec[i]) + SZ(vec[i + 1]));
merge(ALL(vec[i]), ALL(vec[i + 1]), cur.begin());
FOR(j, 0, SZ(cur))
{
if ((c[i] == c[i + 1]) ^ (a[i] / cur[j] == a[i + 1] / cur[j]) ^ 1)
{
events.PB({cur[j], 1});
if (j + 1 < SZ(cur))
events.PB({cur[j + 1], -1});
}
}
}
sort(ALL(events));
int curBal = 0, ans = 0;
FOR(i, 0, SZ(events))
{
auto [x, d] = events[i];
if (curBal == n - 1 && i > 0)
ans += x - events[i - 1].F;
curBal += d;
}
if (curBal == n - 1)
cout << "-1\n";
else
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
4 27 2 2000 4 2015 4 2100 1
output:
277
result:
ok 1 number(s): "277"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
3 1 1 2 2 3 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
20 8009407 2 52139399 1 81888503 1 120671453 1 163862964 1 302398192 2 416701649 1 429974783 3 500470439 4 504724876 4 568950774 1 623322445 2 627708280 3 635420651 2 679274127 4 689823693 4 749262435 3 768217979 2 843577128 3 897415903 4
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
20 120032012 5 246611011 3 265491375 8 267498425 7 270156389 8 288903239 5 302475661 4 307567763 8 361047285 1 394200874 1 420403085 4 501936292 5 600432584 6 626699602 8 678981334 6 687128618 7 793384553 2 894384726 3 922011243 7 935917992 3
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
20 21688482 6 45785260 10 57405982 10 61152073 10 61925336 11 73339674 3 99200321 3 119541327 8 134638414 1 171097635 10 314879815 3 359627504 2 368333671 12 419500072 1 472480245 9 537528257 1 777091904 2 824197754 11 865496235 9 884039712 7
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
20 90255732 3 151927399 11 197517411 15 199943765 15 263163282 14 307986894 16 400502856 10 418087002 8 429062236 7 438154481 1 443761179 11 472704273 1 595553758 2 616236858 4 665937687 2 695128266 11 726080744 11 776934693 5 864473427 2 882378211 12
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
20 12350250 2 101393848 7 163124039 7 169038642 5 172660860 2 312579688 11 324973753 9 367380850 17 372577577 17 393048099 18 472826877 5 479980094 15 673170256 16 703498008 14 708812153 9 721355128 11 768875979 5 786152697 17 824375336 6 857677411 17
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 35ms
memory: 12680kb
input:
20 7965288 1 67493329 1 83012429 1 112009605 1 121005497 1 128328134 1 240579722 2 254164854 2 260562602 2 347043226 2 353722433 2 411689671 3 476857237 3 589494157 3 749337250 3 798456261 3 827764007 3 873420494 4 890044699 4 937179254 4
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 66ms
memory: 24664kb
input:
20 1829956 1 87849977 2 138906566 2 191621867 2 223728466 2 330177095 3 363238055 3 408295374 4 419970864 4 633410645 5 692194086 5 725411576 6 787553402 6 801749874 7 836624360 8 838728757 8 931639285 8 942443737 8 955237179 8 996486142 8
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 80ms
memory: 25392kb
input:
20 9561032 1 49900612 2 152166845 3 268082205 3 268082395 4 291207573 5 331284705 5 342950793 7 444229538 8 444480416 8 460068290 9 507419464 9 597937046 9 650993299 10 791493957 10 807831585 11 828161332 11 905429925 11 915976350 12 988860495 12
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 77ms
memory: 24684kb
input:
20 27113861 2 33772446 2 33898698 5 209358791 6 270877350 8 277607401 8 330017121 8 365908569 9 417277156 9 446815802 10 451870877 10 582507465 11 612077659 13 656445730 13 755031540 15 815614534 15 820589231 15 886422229 16 923573883 16 969504145 16
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 111ms
memory: 41624kb
input:
20 68408841 1 142908584 2 208650662 2 299974515 3 315052252 3 368297717 3 373244049 4 399709157 5 401926762 6 432872466 6 490374482 7 497625347 8 648010985 13 706587111 13 716802434 14 741301662 14 845083938 15 882399127 16 928701618 17 942003924 17
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
1 19047079 10
output:
-1
result:
ok 1 number(s): "-1"
Test #14:
score: 0
Accepted
time: 165ms
memory: 41256kb
input:
20 28853333 1 95681090 2 130145047 3 131111160 4 194504665 5 235400271 6 384267310 7 385955273 8 386292068 9 386502938 10 439878608 11 481953149 12 604563331 13 633365547 14 747320085 15 779947052 16 826084075 17 846219833 18 860509643 19 957210100 20
output:
365011
result:
ok 1 number(s): "365011"
Test #15:
score: 0
Accepted
time: 156ms
memory: 41092kb
input:
20 3176883 1 103301349 2 213155467 3 243845330 4 261629484 5 267384791 6 292806235 7 297855601 8 314820783 9 394183502 10 466572356 11 512435476 12 654339661 13 672214171 14 701009562 15 771020417 16 888901438 17 889854637 18 997173621 19 999430205 20
output:
2460765
result:
ok 1 number(s): "2460765"
Test #16:
score: 0
Accepted
time: 167ms
memory: 41676kb
input:
20 122386362 1 176889927 2 186692596 3 221933882 4 281145854 5 320974414 6 346564856 7 403704956 8 430852333 9 440450417 10 463864449 11 496848534 12 527589016 13 532169980 14 548221944 15 585232612 16 641298291 17 702119355 18 797914291 19 932634235 20
output:
9578182
result:
ok 1 number(s): "9578182"
Test #17:
score: 0
Accepted
time: 161ms
memory: 41804kb
input:
20 43571604 1 45987803 2 130234146 3 209755583 4 222827752 5 225255501 6 306008723 7 389307177 8 405967192 9 484521815 10 507552770 11 513721440 12 596720036 13 649117881 14 676031809 15 679351353 16 700368062 17 762232420 18 870653708 19 908367155 20
output:
3777934
result:
ok 1 number(s): "3777934"
Test #18:
score: 0
Accepted
time: 146ms
memory: 40684kb
input:
20 6233844 1 9241053 2 34858802 3 101157496 4 105284254 5 142633433 6 304033302 7 319009677 8 364387650 9 386499949 10 391881464 11 516339566 12 644205313 13 680747302 14 702760867 15 714306269 16 729094133 17 735085207 18 815092002 19 870060241 20
output:
5401257
result:
ok 1 number(s): "5401257"
Test #19:
score: 0
Accepted
time: 155ms
memory: 40720kb
input:
20 99529611 1 111509914 2 139822611 3 140001053 4 152948499 5 239125720 6 284661965 7 290187975 8 320351843 9 350948064 10 384949811 11 399031878 12 424483857 13 484983558 14 507135585 15 594819524 16 725266031 17 777497121 18 903300735 19 964350508 20
output:
903185
result:
ok 1 number(s): "903185"
Test #20:
score: 0
Accepted
time: 180ms
memory: 41308kb
input:
20 25646402 1 120587860 2 166645803 3 204260156 4 280567055 5 293300898 6 329931339 7 403725131 8 528370381 9 568210753 10 624780656 11 644832641 12 700120384 13 784549578 14 792852181 15 796504228 16 853351756 17 934528734 18 955187783 19 998427585 20
output:
7357503
result:
ok 1 number(s): "7357503"
Test #21:
score: 0
Accepted
time: 181ms
memory: 41136kb
input:
20 2480332 1 80009757 2 193864412 3 314881258 4 320581943 5 351328662 6 408784592 7 419210819 8 442793451 9 547879189 10 599339279 11 606770207 12 649179409 13 686231848 14 772086190 15 852385425 16 877785671 17 918395153 18 926431620 19 952712323 20
output:
9973914
result:
ok 1 number(s): "9973914"
Test #22:
score: 0
Accepted
time: 146ms
memory: 39860kb
input:
20 25030638 1 39498639 2 76173294 3 84376196 4 154381122 5 191893043 6 252246064 7 371126299 8 399181614 9 417394560 10 458064251 11 490307740 12 523176963 13 614051180 14 665960347 15 718828203 16 722480383 17 759122118 18 858738017 19 979082600 20
output:
9109153
result:
ok 1 number(s): "9109153"
Test #23:
score: 0
Accepted
time: 173ms
memory: 40472kb
input:
20 14177909 1 117141110 2 173437468 3 219763853 4 283174518 5 344607884 6 371868088 7 389552806 8 428583134 9 539743954 10 544667084 11 568611208 12 628661503 13 838874069 14 858798205 15 896991484 16 906809250 17 907907215 18 937236615 19 995031898 20
output:
3353371
result:
ok 1 number(s): "3353371"
Test #24:
score: 0
Accepted
time: 72ms
memory: 24300kb
input:
20 53497538 1 74018656 1 78686978 1 88415430 1 99229567 1 187059533 2 269891429 3 313260593 4 329720050 4 332204418 4 337510814 4 338943617 4 339309370 4 605589400 5 623844609 6 647394676 6 717686586 7 800364390 8 816060050 9 835030065 9
output:
537970
result:
ok 1 number(s): "537970"
Test #25:
score: 0
Accepted
time: 42ms
memory: 17308kb
input:
20 140258102 1 247259479 2 296752685 2 310778110 2 325539652 2 327049316 2 392215652 2 401306511 2 446628890 3 458455459 3 634124723 3 639518056 3 713514938 4 760517025 4 788564190 4 803833322 4 841624353 4 965643762 5 986251767 5 993435166 5
output:
10141759
result:
ok 1 number(s): "10141759"
Test #26:
score: 0
Accepted
time: 34ms
memory: 16156kb
input:
20 47013912 1 95972327 1 123272412 1 131184068 1 208901689 1 222195609 1 260128034 2 273268845 2 286104891 2 291762669 2 328039104 2 335950417 2 345767791 2 349134477 2 415160286 2 440407207 2 520743576 3 639761162 3 671447038 3 961222021 4
output:
36312354
result:
ok 1 number(s): "36312354"
Test #27:
score: 0
Accepted
time: 42ms
memory: 16228kb
input:
20 140986750 1 155001141 1 236968782 1 255322440 2 267362176 2 291085853 2 309408072 2 397228713 2 427168000 2 456934021 2 457461547 2 480356788 2 497100661 2 549355483 3 558372676 3 698111403 3 714567659 3 892619701 4 915946251 4 957805157 4
output:
6772109
result:
ok 1 number(s): "6772109"
Test #28:
score: 0
Accepted
time: 62ms
memory: 16248kb
input:
20 24962383 1 41692662 1 44911644 1 112455512 2 133025805 2 160206847 2 190220627 2 268746757 3 282844773 3 286756872 3 304485524 3 355807583 4 381118015 4 403336126 4 412747788 4 418675026 4 704070294 5 837011325 6 866190392 6 895467634 7
output:
3659656
result:
ok 1 number(s): "3659656"
Test #29:
score: 0
Accepted
time: 39ms
memory: 11904kb
input:
20 540733 1 33172752 1 124122447 1 192640515 1 245129634 1 350590181 1 405959006 2 427635887 2 442109297 2 475175459 2 518770965 2 557968829 2 580012508 2 600591817 2 638971992 2 687818792 2 800613512 3 873122675 3 917116628 3 968805117 3
output:
49716575
result:
ok 1 number(s): "49716575"
Test #30:
score: 0
Accepted
time: 30ms
memory: 15092kb
input:
20 26966877 1 27659350 1 32438353 1 43826240 1 70908758 1 95552810 1 240516744 1 271601380 2 281455168 2 348115583 2 395750506 2 473053495 2 497208913 2 646224214 3 715149569 3 734081098 3 764802956 4 943786678 4 965090804 4 967332022 4
output:
6329862
result:
ok 1 number(s): "6329862"
Test #31:
score: 0
Accepted
time: 55ms
memory: 16304kb
input:
20 78936866 1 94328057 1 154231405 2 193262684 2 209355545 2 231362684 2 237935627 2 256614734 2 463742944 3 472980992 3 486918871 3 512600819 3 538594174 4 564662841 4 583401417 4 630680376 4 638251761 4 910784695 5 932918737 6 972681104 6
output:
3162006
result:
ok 1 number(s): "3162006"
Test #32:
score: 0
Accepted
time: 70ms
memory: 23856kb
input:
20 28613013 1 100948747 1 149123677 2 151511925 2 174248089 2 211974630 2 248009281 3 284084374 3 286927739 3 296535028 3 298303431 3 353091430 4 391892139 4 580244261 5 704384030 6 792425818 6 814845995 7 831307773 7 936319932 8 947899483 8
output:
3202882
result:
ok 1 number(s): "3202882"
Test #33:
score: 0
Accepted
time: 65ms
memory: 15864kb
input:
20 2004239 1 229512732 2 269448873 2 311633769 3 330655469 3 334018245 3 339591386 3 431134419 3 489261943 4 502228398 4 516812276 4 582186071 4 628057978 5 666593756 5 678005324 5 795238722 6 809532591 6 833569558 6 864683193 6 949971954 7
output:
10270367
result:
ok 1 number(s): "10270367"
Test #34:
score: 0
Accepted
time: 2ms
memory: 3912kb
input:
2 536870912 1 536870913 2
output:
30
result:
ok 1 number(s): "30"
Test #35:
score: 0
Accepted
time: 2ms
memory: 4100kb
input:
2 536870911 1 536870912 2
output:
8
result:
ok 1 number(s): "8"
Test #36:
score: 0
Accepted
time: 3ms
memory: 5912kb
input:
2 536870912 1 536870913 1
output:
-1
result:
ok 1 number(s): "-1"
Test #37:
score: 0
Accepted
time: 6ms
memory: 5968kb
input:
2 536870911 1 536870912 1
output:
-1
result:
ok 1 number(s): "-1"
Test #38:
score: 0
Accepted
time: 245ms
memory: 74580kb
input:
20 999999981 1 999999982 1 999999983 1 999999984 1 999999985 1 999999986 1 999999987 1 999999988 1 999999989 1 999999990 1 999999991 1 999999992 1 999999993 1 999999994 1 999999995 1 999999996 1 999999997 1 999999998 1 999999999 1 1000000000 1
output:
-1
result:
ok 1 number(s): "-1"