QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21601 | #2848. 城市地铁规划 | gogo# | WA | 12ms | 107660kb | C++20 | 2.4kb | 2022-03-07 16:17:28 | 2022-05-08 03:41:45 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i ++)
#define per(i, r, l) for(int i = (r); i >= (l); i --)
#define trv(i, u, v) for(int i = head[u], v = e[i].to; i; v = e[i = e[i].nxt].to)
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define sz(s) (int)(s.size())
#define lb(s) ((s) & -(s))
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
mt19937_64 hua(time(0));
template<typename T> inline bool chkmx(T &x, T y) {return x < y ? x = y, 1 : 0;}
template<typename T> inline bool chkmn(T &x, T y) {return y < x ? x = y, 1 : 0;}
template<int T> using A = array<int, T>;
inline int read() {
int x = 0, f = 1; char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = 0;
for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return f ? x : -x;
}
const int inf = 1e9;
const int maxn = 3000;
const int maxk = 10;
const int mod = 59393;
int n, k, a[maxk + 5], val[maxn + 5];
P lst[maxn + 5][maxn + 5];
int f[maxn + 5][maxn + 5];
int main() {
//freopen("in.txt", "r", stdin);
n = read(), k = read();
rep(i, 0, k) a[i] = read();
rep(i, 0, n - 1) {
int x = 1;
rep(j, 0, k) {
val[i] = (val[i] + 1ll * x * a[j]) % mod;
x = 1ll * x * i % mod;
}
}
if(n == 1) {
cout << val[0] << '\n';
return 0;
}
ll cur = val[1] * n;
rep(i, 1, n - 2) f[0][i] = -inf;
rep(i, 1, n - 2) {
rep(j, 0, n - 2) {
if(i > j || f[i - 1][j] > f[i][j - i] + val[i + 1] - val[1]) {
f[i][j] = f[i - 1][j];
lst[i][j] = {i - 1, j};
}
else {
f[i][j] = f[i][j - i] + val[i + 1] - val[1];
lst[i][j] = {i, j - i};
}
}
}
cout << n - 1<< ' ' << cur + f[n - 2][n - 2] << '\n';
vector<int> s;
function<void(int, int)> dfs = [&] (int i, int j) {
if(!i) return ;
if(lst[i][j].se != j) s.pb(j - lst[i][j].se + 1);
dfs(lst[i][j].fi, lst[i][j].se);
};
dfs(n - 2, n - 2);
while(sz(s) < n) s.pb(1);
sort(all(s));
reverse(all(s));
deque<P> q;
rep(i, 0, sz(s) - 1) q.push_back({s[i], i + 1});// cout << s[i] << ' ' << i + 1 << '\n';
vector<P> ans;
rep(i, 1, n - 2) {
assert(q.back().fi == 1);
ans.pb({q.back().se, q.front().se});
q.pop_back();
q[0].fi --;
if(q[0].fi == 1) {
P x = q[0];
q.pop_front();
q.push_back(x);
}
}
assert(sz(q) == 2);
ans.pb({q[0].se, q[1].se});
rep(i, 0, n - 2) cout << ans[i].fi << ' ' << ans[i].se << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8012kb
input:
63 7 4 50 14 48 33 13 44 24
output:
62 992106 63 1 62 1 1 2 61 2 2 3 60 3 3 4 59 4 4 5 58 5 5 6 57 6 6 7 56 7 7 8 55 8 8 9 54 9 9 10 53 10 10 11 52 11 11 12 51 12 12 13 50 13 13 14 49 14 14 15 48 15 15 16 47 16 16 17 46 17 17 18 45 18 18 19 44 19 19 20 43 20 20 21 42 21 21 22 41 22 22 23 40 23 23 24 39 24 24 25 38 25 25 26 37 26 26 27...
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 12420kb
input:
208 7 23 28 14 16 46 28 26 28
output:
207 3317121 208 1 207 1 1 2 206 2 2 3 205 3 3 4 204 4 4 5 203 5 5 6 202 6 6 7 201 7 7 8 200 8 8 9 199 9 9 10 198 10 10 11 197 11 11 12 196 12 12 13 195 13 13 14 194 14 14 15 193 15 15 16 192 16 16 17 191 17 17 18 190 18 18 19 189 19 19 20 188 20 20 21 187 21 21 22 186 22 22 23 185 23 23 24 184 24 24...
result:
ok
Test #3:
score: 0
Accepted
time: 12ms
memory: 107660kb
input:
2928 3 27 20 7 29
output:
2927 13889888 2928 1 2927 1 2926 1 2925 1 2924 1 2923 1 2922 1 2921 1 2920 1 2919 1 2918 1 1 2 2917 2 2916 2 2915 2 2914 2 2913 2 2912 2 2911 2 2910 2 2909 2 2908 2 2 3 2907 3 2906 3 2905 3 2904 3 2903 3 2902 3 2901 3 2900 3 2899 3 2898 3 3 4 2897 4 2896 4 2895 4 2894 4 2893 4 2892 4 2891 4 2890 4 2...
result:
ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 13408kb
input:
320 3 46 42 15 15
output:
319 1260206 320 1 319 1 318 1 317 1 316 1 315 1 314 1 313 1 312 1 311 1 310 1 309 1 308 1 307 1 1 2 306 2 305 2 304 2 303 2 302 2 301 2 300 2 299 2 298 2 297 2 296 2 295 2 294 2 2 3 293 3 292 3 291 3 290 3 289 3 288 3 287 3 286 3 285 3 284 3 283 3 282 3 281 3 3 4 280 4 279 4 278 4 277 4 276 4 275 4 ...
result:
ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 13944kb
input:
380 5 41 27 8 3 31 0
output:
379 3140470 380 1 379 1 378 1 377 1 376 1 1 2 375 2 374 2 373 2 372 2 2 3 371 3 370 3 369 3 368 3 3 4 367 4 366 4 365 4 364 4 4 5 363 5 362 5 361 5 360 5 5 6 359 6 358 6 357 6 356 6 6 7 355 7 354 7 353 7 352 7 7 8 351 8 350 8 349 8 348 8 8 9 347 9 346 9 345 9 344 9 9 10 343 10 342 10 341 10 340 10 1...
result:
ok
Test #6:
score: 0
Accepted
time: 2ms
memory: 13484kb
input:
365 5 35 20 24 29 3 25
output:
364 3508667 365 1 364 1 363 1 1 2 362 2 361 2 2 3 360 3 359 3 3 4 358 4 357 4 4 5 356 5 355 5 5 6 354 6 353 6 6 7 352 7 351 7 7 8 350 8 349 8 8 9 348 9 347 9 9 10 346 10 345 10 10 11 344 11 343 11 11 12 342 12 341 12 12 13 340 13 339 13 13 14 338 14 337 14 14 15 336 15 335 15 15 16 334 16 333 16 16 ...
result:
ok
Test #7:
score: 0
Accepted
time: 2ms
memory: 13120kb
input:
318 6 4 44 46 6 37 14 49
output:
317 6799456 318 1 317 1 1 2 316 2 2 3 315 3 3 4 314 4 4 5 313 5 5 6 312 6 6 7 311 7 7 8 310 8 8 9 309 9 9 10 308 10 10 11 307 11 11 12 306 12 12 13 305 13 13 14 304 14 14 15 303 15 15 16 302 16 16 17 301 17 17 18 300 18 18 19 299 19 19 20 298 20 20 21 297 21 21 22 296 22 22 23 295 23 23 24 294 24 24...
result:
ok
Test #8:
score: 0
Accepted
time: 3ms
memory: 14884kb
input:
416 6 30 23 4 16 45 32 19
output:
415 5383994 416 1 415 1 1 2 414 2 2 3 413 3 3 4 412 4 4 5 411 5 5 6 410 6 6 7 409 7 7 8 408 8 8 9 407 9 9 10 406 10 10 11 405 11 11 12 404 12 12 13 403 13 13 14 402 14 14 15 401 15 15 16 400 16 16 17 399 17 17 18 398 18 18 19 397 19 19 20 396 20 20 21 395 21 21 22 394 22 22 23 393 23 23 24 392 24 24...
result:
ok
Test #9:
score: 0
Accepted
time: 2ms
memory: 16988kb
input:
572 5 15 27 5 18 3 46
output:
571 9396678 572 1 571 1 570 1 1 2 569 2 568 2 2 3 567 3 566 3 3 4 565 4 564 4 4 5 563 5 562 5 5 6 561 6 560 6 6 7 559 7 558 7 7 8 557 8 556 8 8 9 555 9 554 9 9 10 553 10 552 10 10 11 551 11 550 11 11 12 549 12 548 12 12 13 547 13 546 13 13 14 545 14 544 14 14 15 543 15 542 15 15 16 541 16 540 16 16 ...
result:
ok
Test #10:
score: 0
Accepted
time: 2ms
memory: 16672kb
input:
531 8 20 13 35 27 41 43 36 25 5
output:
530 9024252 531 1 530 1 529 1 1 2 528 2 527 2 2 3 526 3 525 3 3 4 524 4 523 4 4 5 522 5 521 5 5 6 520 6 519 6 6 7 518 7 517 7 7 8 516 8 515 8 8 9 514 9 513 9 9 10 512 10 511 10 10 11 510 11 509 11 11 12 508 12 507 12 12 13 506 13 505 13 13 14 504 14 503 14 14 15 502 15 501 15 15 16 500 16 499 16 16 ...
result:
ok
Test #11:
score: 0
Accepted
time: 3ms
memory: 15600kb
input:
487 10 29 29 40 45 5 16 40 47 47 2 14
output:
486 18026623 487 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
result:
ok
Test #12:
score: 0
Accepted
time: 2ms
memory: 17544kb
input:
584 7 10 27 29 8 32 43 26 3
output:
583 11437238 584 1 583 1 1 2 582 2 2 3 581 3 3 4 580 4 4 5 579 5 5 6 578 6 6 7 577 7 7 8 576 8 8 9 575 9 9 10 574 10 10 11 573 11 11 12 572 12 12 13 571 13 13 14 570 14 14 15 569 15 15 16 568 16 16 17 567 17 17 18 566 18 18 19 565 19 19 20 564 20 20 21 563 21 21 22 562 22 22 23 561 23 23 24 560 24 2...
result:
ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 7848kb
input:
59 4 48 16 9 42 21
output:
58 422967 59 1 58 1 57 1 56 1 55 1 54 1 53 1 1 2 52 2 51 2 50 2 49 2 2 3 48 3 47 3 46 3 45 3 3 4 44 4 43 4 42 4 41 4 4 5 40 5 39 5 38 5 37 5 5 6 36 6 35 6 34 6 33 6 6 7 32 7 31 7 30 7 29 7 7 8 28 8 27 8 26 8 25 8 8 9 24 9 23 9 22 9 21 9 9 10 20 10 19 10 18 10 17 10 10 11 16 11 15 11 14 11 13 11 12 11
result:
ok
Test #14:
score: 0
Accepted
time: 2ms
memory: 16936kb
input:
561 3 22 31 17 49
output:
560 3223790 561 1 560 1 559 1 558 1 557 1 556 1 555 1 554 1 553 1 1 2 552 2 551 2 550 2 549 2 548 2 547 2 546 2 545 2 2 3 544 3 543 3 542 3 541 3 540 3 539 3 538 3 537 3 3 4 536 4 535 4 534 4 533 4 532 4 531 4 530 4 529 4 4 5 528 5 527 5 526 5 525 5 524 5 523 5 522 5 521 5 5 6 520 6 519 6 518 6 517 ...
result:
ok
Test #15:
score: 0
Accepted
time: 2ms
memory: 18628kb
input:
629 6 26 31 41 32 13 39 41
output:
628 13149156 629 1 628 1 1 2 627 2 2 3 626 3 3 4 625 4 4 5 624 5 5 6 623 6 6 7 622 7 7 8 621 8 8 9 620 9 9 10 619 10 10 11 618 11 11 12 617 12 12 13 616 13 13 14 615 14 14 15 614 15 15 16 613 16 16 17 612 17 17 18 611 18 18 19 610 19 19 20 609 20 20 21 608 21 21 22 607 22 22 23 606 23 23 24 605 24 2...
result:
ok
Test #16:
score: 0
Accepted
time: 2ms
memory: 18440kb
input:
616 3 38 48 27 2
output:
615 1394108 616 1 615 1 614 1 613 1 612 1 611 1 610 1 609 1 608 1 607 1 606 1 605 1 604 1 603 1 602 1 601 1 600 1 599 1 598 1 597 1 596 1 595 1 594 1 593 1 592 1 1 2 591 2 590 2 589 2 588 2 587 2 586 2 585 2 584 2 583 2 582 2 581 2 580 2 579 2 578 2 577 2 576 2 575 2 574 2 573 2 572 2 571 2 570 2 56...
result:
ok
Test #17:
score: 0
Accepted
time: 3ms
memory: 20688kb
input:
744 2 49 45 50
output:
743 1425426 744 1 743 1 742 1 741 1 740 1 739 1 738 1 737 1 736 1 735 1 734 1 733 1 732 1 731 1 730 1 729 1 728 1 727 1 726 1 725 1 724 1 723 1 722 1 721 1 720 1 719 1 718 1 717 1 716 1 715 1 714 1 713 1 712 1 1 2 711 2 710 2 709 2 708 2 707 2 706 2 705 2 704 2 703 2 702 2 701 2 700 2 699 2 698 2 69...
result:
ok
Test #18:
score: 0
Accepted
time: 9ms
memory: 18680kb
input:
629 7 27 18 48 24 37 38 6 3
output:
628 9258317 629 1 628 1 627 1 626 1 1 2 625 2 624 2 623 2 2 3 622 3 621 3 620 3 3 4 619 4 618 4 617 4 4 5 616 5 615 5 614 5 5 6 613 6 612 6 611 6 6 7 610 7 609 7 608 7 7 8 607 8 606 8 605 8 8 9 604 9 603 9 602 9 9 10 601 10 600 10 599 10 10 11 598 11 597 11 596 11 11 12 595 12 594 12 593 12 12 13 59...
result:
ok
Test #19:
score: 0
Accepted
time: 2ms
memory: 18152kb
input:
602 8 17 25 14 13 2 16 23 24 44
output:
601 9947756 602 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51...
result:
ok
Test #20:
score: 0
Accepted
time: 7ms
memory: 25212kb
input:
900 2 9 13 12
output:
899 787522 900 1 899 1 898 1 897 1 896 1 895 1 894 1 893 1 892 1 891 1 890 1 889 1 888 1 887 1 886 1 885 1 884 1 883 1 882 1 881 1 880 1 879 1 878 1 877 1 876 1 875 1 874 1 873 1 872 1 871 1 870 1 869 1 868 1 867 1 866 1 865 1 864 1 863 1 862 1 861 1 860 1 859 1 858 1 857 1 856 1 855 1 854 1 853 1 8...
result:
ok
Test #21:
score: 0
Accepted
time: 2ms
memory: 23272kb
input:
839 7 12 12 28 33 35 29 14 17
output:
838 24516016 839 1 838 1 1 2 837 2 2 3 836 3 3 4 835 4 4 5 834 5 5 6 833 6 6 7 832 7 7 8 831 8 8 9 830 9 9 10 829 10 10 11 828 11 11 12 827 12 12 13 826 13 13 14 825 14 14 15 824 15 15 16 823 16 16 17 822 17 17 18 821 18 18 19 820 19 19 20 819 20 20 21 818 21 21 22 817 22 22 23 816 23 23 24 815 24 2...
result:
ok
Test #22:
score: 0
Accepted
time: 2ms
memory: 21572kb
input:
768 7 27 3 40 6 39 9 48 31
output:
767 18960055 768 1 767 1 1 2 766 2 2 3 765 3 3 4 764 4 4 5 763 5 5 6 762 6 6 7 761 7 7 8 760 8 8 9 759 9 9 10 758 10 10 11 757 11 11 12 756 12 12 13 755 13 13 14 754 14 14 15 753 15 15 16 752 16 16 17 751 17 17 18 750 18 18 19 749 19 19 20 748 20 20 21 747 21 21 22 746 22 22 23 745 23 23 24 744 24 2...
result:
ok
Test #23:
score: 0
Accepted
time: 2ms
memory: 21524kb
input:
783 3 25 19 31 45
output:
782 4263811 783 1 782 1 781 1 780 1 779 1 778 1 777 1 776 1 775 1 1 2 774 2 773 2 772 2 771 2 770 2 769 2 768 2 767 2 2 3 766 3 765 3 764 3 763 3 762 3 761 3 760 3 759 3 3 4 758 4 757 4 756 4 755 4 754 4 753 4 752 4 751 4 4 5 750 5 749 5 748 5 747 5 746 5 745 5 744 5 743 5 5 6 742 6 741 6 740 6 739 ...
result:
ok
Test #24:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
2 4 24 9 31 45 15
output:
1 248 1 2
result:
ok
Test #25:
score: 0
Accepted
time: 3ms
memory: 22032kb
input:
792 5 28 40 21 32 44 11
output:
791 6695732 792 1 791 1 790 1 1 2 789 2 788 2 2 3 787 3 786 3 3 4 785 4 784 4 4 5 783 5 782 5 5 6 781 6 780 6 6 7 779 7 778 7 7 8 777 8 776 8 8 9 775 9 774 9 9 10 773 10 772 10 10 11 771 11 770 11 11 12 769 12 768 12 12 13 767 13 766 13 13 14 765 14 764 14 14 15 763 15 762 15 15 16 761 16 760 16 16 ...
result:
ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 25892kb
input:
939 5 35 7 31 40 25 28
output:
938 12031060 939 1 938 1 937 1 936 1 1 2 935 2 934 2 2 3 933 3 932 3 3 4 931 4 930 4 4 5 929 5 928 5 5 6 927 6 926 6 6 7 925 7 924 7 7 8 923 8 922 8 8 9 921 9 920 9 9 10 919 10 918 10 10 11 917 11 916 11 11 12 915 12 914 12 12 13 913 13 912 13 13 14 911 14 910 14 14 15 909 15 908 15 15 16 907 16 906...
result:
ok
Test #27:
score: 0
Accepted
time: 2ms
memory: 25816kb
input:
924 6 30 26 21 8 12 42 26
output:
923 14203740 924 1 923 1 1 2 922 2 2 3 921 3 3 4 920 4 4 5 919 5 5 6 918 6 6 7 917 7 7 8 916 8 8 9 915 9 9 10 914 10 10 11 913 11 11 12 912 12 12 13 911 13 13 14 910 14 14 15 909 15 15 16 908 16 16 17 907 17 17 18 906 18 18 19 905 19 19 20 904 20 20 21 903 21 21 22 902 22 22 23 901 23 23 24 900 24 2...
result:
ok
Test #28:
score: 0
Accepted
time: 6ms
memory: 25404kb
input:
902 8 8 48 35 25 32 28 21 2 44
output:
901 13244886 902 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
result:
ok
Test #29:
score: 0
Accepted
time: 5ms
memory: 28712kb
input:
1021 2 11 16 14
output:
1020 977447 1021 1 1020 1 1019 1 1018 1 1017 1 1016 1 1015 1 1014 1 1013 1 1012 1 1011 1 1010 1 1009 1 1008 1 1007 1 1006 1 1005 1 1004 1 1003 1 1002 1 1001 1 1000 1 999 1 998 1 997 1 996 1 995 1 994 1 993 1 992 1 991 1 990 1 989 1 988 1 987 1 986 1 985 1 984 1 983 1 982 1 981 1 980 1 979 1 978 1 97...
result:
ok
Test #30:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
1 9 18 7 32 20 44 12 15 38 14 43
output:
18
result:
wrong output format Unexpected end of file - int32 expected