QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270211 | #4852. Restorani | zhouhuanyi | AC ✓ | 104ms | 8196kb | C++20 | 3.0kb | 2023-11-30 16:34:07 | 2023-11-30 16:34:07 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<bitset>
#include<algorithm>
#define N 1000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int num,data;
bool operator < (const reads &t)const
{
return data<t.data;
}
};
reads tong[N+1];
int n,cater,X[N+1],Y[N+1],dfn[N+1],low[N+1],delta[N+1],dp[N+1][N+1],DP[N+1],belong[N+1];
bitset<N+1>E[N+1];
bitset<N+1>E2[N+1];
bitset<N+1>E3[N+1];
bitset<N+1>used;
vector<int>v[N+1];
stack<int>st;
void dfs(int x)
{
bitset<N+1>B=E[x]&used;
for (int i=B._Find_first();i!=B.size();i=B._Find_next(i)) used[i]=0;
for (int i=B._Find_first();i!=B.size();i=B._Find_next(i)) dfs(i);
return;
}
void tarjan(int x)
{
dfn[x]=low[x]=++dfn[0],st.push(x),used[x]=1;
for (int i=1;i<=n;++i)
if (E2[x][i])
{
if (!dfn[i]) tarjan(i),low[x]=min(low[x],low[i]);
else if (used[i]) low[x]=min(low[x],dfn[i]);
}
if (dfn[x]==low[x])
{
++cater;
while (st.top()!=x) belong[st.top()]=cater,used[st.top()]=0,st.pop();
belong[st.top()]=cater,used[st.top()]=0,st.pop();
}
return;
}
bool cmp(int x,int y)
{
return X[x]<X[y];
}
int main()
{
int x,f,cnt,res;
n=read();
for (int i=1;i<=n;++i)
{
X[i]=read(),Y[i]=read(),f=read();
while (f--) x=read(),E[i][x]=1;
}
for (int i=1;i<=n;++i)
{
used.set(),used[i]=0,dfs(i);
for (int j=1;j<=n;++j)
if (i!=j&&!used[j])
E2[i][j]=1;
}
used.reset();
for (int i=1;i<=n;++i)
if (!dfn[i])
tarjan(i);
for (int i=1;i<=n;++i) v[belong[i]].push_back(i);
for (int i=1;i<=cater;++i)
{
sort(v[i].begin(),v[i].end(),cmp);
for (int j=1;j<=v[i].size();++j) DP[j]=inf;
for (int j=0;j<v[i].size();++j)
{
cnt=1,res=Y[v[i][j]],DP[1]=min(DP[1],res);
for (int k=0;k<v[i].size();++k)
if (j!=k)
cnt++,res+=X[v[i][k]],DP[cnt]=min(DP[cnt],res);
}
for (int j=1;j<=v[i].size();++j) delta[v[i][j-1]]=DP[j]-DP[j-1];
for (int j=2;j<=v[i].size();++j) E3[v[i][j-2]][v[i][j-1]]=1;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if (E2[i][j]&&belong[i]!=belong[j]&&v[belong[j]][0]==j)
E3[i][j]=1;
for (int i=1;i<=n;++i)
{
DP[i]=inf;
for (int j=1;j<=n;++j) dp[i][j]=inf;
}
for (int i=1;i<=n;++i)
if (v[belong[i]][0]==i)
dp[1][i]=delta[i];
for (int i=2;i<=n;++i)
{
for (int j=1;j<=n;++j) tong[j]=(reads){j,dp[i-1][j]};
sort(tong+1,tong+n+1),used.set();
for (int j=1;j<=n;++j)
{
bitset<N+1>B=used&E3[tong[j].num];
for (int k=B._Find_first();k!=B.size();k=B._Find_next(k)) dp[i][k]=min(dp[i][k],tong[j].data+delta[k]),used[k]=0;
}
}
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
DP[i]=min(DP[i],dp[i][j]);
for (int i=1;i<=n;++i)
if (DP[i]!=inf)
printf("%d\n",DP[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 97ms
memory: 7968kb
input:
1000 2856 4225 9 773 772 383 359 750 327 752 465 612 5478 5990 6 452 449 938 60 930 374 2088 2765 3 703 416 845 8905 1853 3 891 518 651 8249 9640 5 844 126 767 602 549 8956 9158 5 321 126 633 228 147 115 559 10 996 649 568 530 473 268 457 746 815 758 7208 9975 8 164 365 391 481 821 587 964 118 2260 ...
output:
56 57 63 85 107 131 155 180 207 237 270 305 340 380 426 473 536 618 704 794 885 977 1076 1186 1297 1409 1524 1640 1759 1882 2005 2130 2257 2398 2543 2688 2838 2994 3152 3319 3490 3665 3840 4027 4216 4405 4614 4824 5036 5249 5462 5682 5903 6139 6379 6622 6867 7114 7368 7626 7893 8162 8434 8709 8985 9...
result:
ok 1000 lines
Test #2:
score: 0
Accepted
time: 70ms
memory: 7988kb
input:
1000 4409 7088 4 774 678 552 582 600 7071 4 386 128 135 393 154 205 5 508 106 866 374 384 390 5420 9 881 365 543 784 801 730 413 177 200 2470 3366 3 314 905 772 5563 9537 4 372 357 628 691 5281 6770 2 595 761 3436 9375 3 641 338 668 2113 2528 1 742 3114 8123 6 479 145 736 802 354 764 304 2375 2 529 ...
output:
175 473 898 1350 1775 2264 2780 3205 3694 4273 4902 5481 6131 6878 7659 8408 9171 9952 10701 11482 12265 13046 13905 14724 15583 16444 17303 18165 19046 19948 20829 21743 22681 23602 24516 25454 26411 27371 28328 29335 30379 31381 32388 33432 34472 35516 36541 37585 38625 39669 40695 41739 42779 438...
result:
ok 524 lines
Test #3:
score: 0
Accepted
time: 73ms
memory: 7996kb
input:
1000 6573 6343 7 845 452 5 335 808 278 235 4070 694 7 579 684 526 844 398 119 553 1939 1203 5 984 865 266 848 741 9791 887 9 674 908 87 619 78 913 148 516 195 4876 3790 4 649 861 324 808 7489 7202 6 874 552 375 822 819 136 7856 7046 7 726 743 720 396 214 423 809 6982 4791 5 635 318 183 1 518 4220 18...
output:
5 16 37 59 95 136 189 258 344 442 543 645 750 855 983 1127 1273 1421 1580 1740 1942 2161 2385 2614 2870 3202 3601 4026 4497 4994 5511 6047 6624 7259 7862 8515 9176 9852 10557 11361 12185 13072 13981 14921 15867 16927 18036 19176 20354 21536 22725 23977 25240 26557 27879 29227 30609 32078 33570 35144...
result:
ok 556 lines
Test #4:
score: 0
Accepted
time: 86ms
memory: 7956kb
input:
1000 1663 6267 12 435 180 900 697 397 561 145 874 775 81 654 756 5064 7684 8 972 395 665 248 370 559 671 593 3133 4544 18 357 189 739 37 960 737 388 480 234 866 986 617 45 216 538 916 239 991 794 8421 9 391 698 153 737 220 592 496 134 986 2527 7153 16 229 830 165 841 631 247 393 565 508 541 608 996 ...
output:
86 94 183 299 421 510 626 757 937 1060 1167 1283 1414 1582 1737 1863 1979 2108 2239 2419 2562 2693 2841 3021 3191 3339 3519 3710 3915 4123 4358 4594 4828 5036 5253 5488 5724 5961 6202 6437 6673 6910 7158 7408 7660 7914 8179 8451 8729 9022 9333 9625 9910 10182 10460 10753 11056 11356 11649 11952 1227...
result:
ok 1000 lines
Test #5:
score: 0
Accepted
time: 93ms
memory: 7928kb
input:
1000 1747 7625 280 480 863 106 253 808 346 121 2 634 987 971 520 169 256 665 531 940 905 347 545 718 594 341 683 489 995 291 411 551 728 592 149 390 404 125 414 4 979 530 36 983 723 637 434 955 891 885 880 386 899 189 796 910 447 400 574 522 329 115 333 470 463 161 550 16 760 524 64 605 465 101 928 ...
output:
3 8 82 115 189 472 561 652 862 1024 1125 1325 1497 1697 1911 2266 2507 2729 3084 3325 3581 3936 4177 4499 4854 5095 5450 5807 6169 6535 6916 7197 7552 7909 8271 8637 9018 9398 9764 10145 10530 10910 11276 11657 12056 12465 12849 13248 13657 14059 14458 14867 15291 15699 16108 16532 16956 17390 17814...
result:
ok 1000 lines
Test #6:
score: 0
Accepted
time: 80ms
memory: 7940kb
input:
1000 1067 2913 213 35 514 782 791 913 662 337 403 630 318 698 119 416 214 520 418 381 356 253 289 228 458 378 577 412 271 290 839 894 26 469 982 978 957 446 413 104 170 246 604 774 365 830 713 238 232 787 52 18 964 786 17 261 828 3 781 302 943 704 42 96 188 870 790 840 242 547 799 180 558 7 265 353 ...
output:
5 72 199 334 486 664 827 1005 1171 1349 1531 1720 1915 2119 2326 2587 2807 3068 3333 3626 3891 4216 4503 4828 5137 5462 5812 6138 6488 6871 7221 7604 7975 8358 8749 9141 9577 10026 10418 10854 11305 11697 12133 12610 13088 13549 13985 14462 14940 15424 15902 16390 16874 17352 17845 18385 18882 19422...
result:
ok 1000 lines
Test #7:
score: 0
Accepted
time: 88ms
memory: 7928kb
input:
1000 4848 7639 272 53 598 506 790 315 415 940 757 294 325 223 108 363 173 416 378 51 876 102 149 42 101 478 483 339 745 806 631 695 820 227 697 308 72 774 323 304 135 74 188 694 277 322 610 324 33 459 842 972 660 990 650 662 821 383 337 474 296 538 903 194 122 412 914 193 521 278 712 299 418 120 596...
output:
34 86 158 312 531 685 843 997 1171 1370 1544 1780 2011 2185 2404 2640 2883 3121 3357 3600 3856 4112 4365 4621 4877 5133 5391 5647 5903 6174 6455 6721 6992 7269 7550 7843 8161 8481 8774 9092 9412 9739 10072 10412 10733 11060 11393 11751 12078 12411 12765 13098 13456 13783 14116 14483 14853 15223 1559...
result:
ok 1000 lines
Test #8:
score: 0
Accepted
time: 90ms
memory: 8096kb
input:
1000 4872 9237 1 137 3366 4870 5 230 281 710 143 288 1642 4767 2 345 217 6136 6577 5 330 631 523 69 790 5756 9186 3 66 652 211 2410 5877 4 100 664 206 436 1193 9537 1 610 294 675 2 613 813 6128 9728 3 138 675 691 1107 1812 3 736 16 313 4120 9991 3 752 901 18 6824 7382 2 342 200 244 3991 4 322 441 51...
output:
38 40 43 47 52 58 74 97 128 161 194 231 269 308 352 399 450 513 577 644 711 779 852 936 1023 1111 1199 1291 1385 1480 1578 1680 1783 1890 2005 2122 2240 2366 2510 2673 2842 3012 3185 3361 3537 3720 3908 4106 4313 4534 4761 4988 5217 5456 5697 5940 6184 6429 6677 6927 7182 7440 7699 7964 8231 8500 87...
result:
ok 879 lines
Test #9:
score: 0
Accepted
time: 43ms
memory: 7996kb
input:
1000 4481 7277 3 729 293 266 303 1177 1 25 6990 7626 1 682 1518 5367 0 988 4277 3 311 104 201 4264 6773 1 692 7887 8132 1 280 3087 7960 0 4108 7548 0 7264 7660 1 919 5039 8599 1 837 5292 8954 0 8261 9774 1 251 1571 2164 0 2022 5035 0 8910 9514 2 694 540 3937 5802 1 353 1530 6001 3 146 81 122 8267 93...
output:
30 461 1312 1643 2176 2822 3562 4560 5784 7211 9171 11329 13790 16828 20133 23560 27083 30919 34982 39259 44163 49526 55300 61413 68386 75388 82566 89903 97378 105488 113667 122178 130947 139986 148755 157899 167514 182248 192367
result:
ok 39 lines
Test #10:
score: 0
Accepted
time: 104ms
memory: 8052kb
input:
1000 3069 8345 3 799 527 839 1530 3406 8 255 35 964 713 590 723 733 290 246 3570 4 224 883 609 311 1776 6840 8 563 630 292 594 743 826 209 820 1832 4127 14 151 943 396 133 305 936 544 998 951 641 113 298 1000 365 205 8462 10 827 145 667 420 789 160 396 91 980 628 1252 5371 9 766 972 682 705 495 452 ...
output:
66 68 71 75 80 86 108 132 171 215 259 310 361 424 488 559 633 712 793 877 961 1054 1151 1252 1362 1478 1596 1720 1856 1993 2136 2285 2438 2592 2752 2913 3085 3258 3432 3607 3785 3965 4158 4362 4567 4772 4981 5193 5423 5657 5902 6148 6398 6664 6938 7215 7493 7771 8055 8341 8630 8923 9217 9511 9812 10...
result:
ok 998 lines
Test #11:
score: 0
Accepted
time: 83ms
memory: 8000kb
input:
1000 5861 8836 5 137 419 523 554 731 540 9221 2 374 338 4584 7909 11 501 742 589 236 987 980 141 32 977 218 991 3272 8281 9 947 276 278 567 462 714 945 394 413 1810 9701 7 64 916 237 153 870 303 779 2245 6798 28 992 560 693 12 503 125 635 282 118 288 293 263 50 71 799 938 776 470 131 665 375 557 699...
output:
155 165 185 218 251 285 330 379 428 502 591 684 787 903 1020 1143 1273 1411 1561 1711 1864 2018 2174 2336 2499 2670 2844 3021 3201 3389 3578 3782 3989 4199 4426 4655 4887 5126 5365 5607 5855 6111 6369 6632 6898 7166 7450 7740 8032 8327 8626 8927 9229 9532 9844 10159 10475 10791 11113 11446 11781 121...
result:
ok 782 lines
Test #12:
score: 0
Accepted
time: 43ms
memory: 7964kb
input:
1000 849 4491 1 742 3166 4901 3 272 96 764 6559 7578 1 839 992 6547 1 184 316 4385 1 531 4719 6369 0 6775 8115 1 172 149 7879 2 956 399 2952 7544 1 265 4650 2242 2 819 693 6771 9763 2 638 14 2820 8794 1 524 6319 8615 2 455 205 2344 9065 3 883 638 11 1416 3681 0 2413 9688 1 982 1922 4942 1 576 952 90...
output:
221 384 1411 3380 6261
result:
ok 5 lines
Test #13:
score: 0
Accepted
time: 86ms
memory: 8020kb
input:
1000 909 3676 134 960 190 275 119 634 993 344 101 277 270 158 148 289 890 904 236 529 139 811 76 705 941 66 389 181 607 512 363 878 321 320 633 142 212 407 552 24 846 521 147 870 940 978 286 945 719 628 636 696 541 195 673 437 7 368 75 613 95 716 423 765 554 654 777 854 860 511 247 663 367 990 369 3...
output:
221 223 229 261 298 336 379 429 479 534 593 656 722 799 880 962 1046 1135 1224 1316 1408 1504 1610 1730 1850 1974 2099 2226 2364 2509 2665 2821 2978 3136 3302 3470 3640 3812 3984 4163 4344 4526 4717 4910 5108 5309 5517 5726 5935 6146 6362 6581 6800 7024 7248 7484 7721 7967 8213 8461 8733 9010 9296 9...
result:
ok 959 lines
Test #14:
score: 0
Accepted
time: 85ms
memory: 8196kb
input:
1000 900 6230 1 431 2035 5062 1 642 299 5130 1 341 7459 7586 1 143 2950 9083 1 915 2349 7327 1 590 5226 9653 1 233 4435 6152 1 236 28 1803 1 363 2518 9856 1 196 7205 7733 1 149 1137 1511 1 67 304 1731 1 381 2977 5944 1 870 4246 9914 1 183 1932 9992 1 445 455 8003 1 197 1427 1915 1 532 4083 7903 1 69...
output:
301 808 1323 1860 2445 3034 3679 4343 5108 5877 6704 7596 8562 9547 10559 11596 12646 13723 14807 15895 17002 18121 19240 20366 21507 22678 23853 25050 26360 27673 29008 30390 31805 33295 34802 36313 37824 39344 40881 42445 44049 45655 47280 48942 50608 52295 54024 55755 57504 59254 61006 62809 6463...
result:
ok 1000 lines
Test #15:
score: 0
Accepted
time: 89ms
memory: 8060kb
input:
1000 1346 7063 6 804 55 448 866 239 929 55 1232 7 79 9 52 855 679 346 850 1191 2565 11 479 385 70 624 819 187 352 573 260 130 394 7788 7911 19 907 901 975 451 407 691 707 757 148 301 431 842 164 607 103 574 861 905 78 2969 6157 8 902 655 709 775 515 126 401 182 645 3249 6 727 968 388 982 589 220 813...
output:
1 348 372 415 465 517 571 626 682 749 831 914 998 1106 1225 1359 1508 1658 1810 1970 2148 2327 2514 2720 2928 3136 3352 3583 3834 4085 4362 4644 4929 5227 5533 5818 6116 6434 6784 7150 7535 7920 8312 8715 9121 9529 9950 10377 10798 11230 11678 12130 12587 13054 13528 14003 14505 15017 15535 16062 16...
result:
ok 1000 lines
Test #16:
score: 0
Accepted
time: 49ms
memory: 7940kb
input:
1000 315 6305 8 496 374 785 576 216 855 73 565 2225 4247 7 299 453 645 98 100 810 264 921 1965 4 139 363 169 755 2557 5068 6 652 600 714 815 903 908 8537 9998 1 462 3507 9952 2 868 22 9545 2652 6 109 90 91 598 557 291 2326 9200 3 170 793 974 6920 7538 6 507 100 72 645 790 450 183 4587 3 908 918 70 9...
output:
4 51 422 516 596 799 1065 1237 1420 1623 1889 2167 2538 2874 3152 3521 3892 4267 4649 5045 5482 5945 6414 6904 7414 7944 8497 9079 9654 10207 10774 11327 11904 12484 13037 13614 14196 14786 15441 16166 16923 17708 18506 19321 20141 20983 21805 22735 23681 24570 25364 26163 27093 28039 29027 30023 31...
result:
ok 219 lines
Test #17:
score: 0
Accepted
time: 52ms
memory: 8008kb
input:
1000 1470 8077 4 336 621 339 244 320 1263 6 966 212 30 374 301 724 483 688 6 856 609 778 41 548 570 114 368 4 520 378 808 255 8336 9994 1 215 1346 2259 5 894 186 494 963 414 1082 3755 7 871 149 266 453 38 265 259 2664 3135 5 415 993 538 466 197 2638 7039 2 323 60 770 5321 5 532 877 170 189 446 832 2...
output:
55 75 95 161 234 462 630 819 1043 1271 1627 1995 2223 2454 2690 3009 3365 3739 3970 4206 4525 4881 5260 5727 6334 6956 7588 8247 8907 9572 10273 11039 11871 12733 13667 14606 15580 16598 17624 18651 19684 20759 21836 22927 24029 25158 26351 27430 28364 29254 30166 31105 32052 33015 33987 34979 35982...
result:
ok 216 lines
Test #18:
score: 0
Accepted
time: 70ms
memory: 7972kb
input:
1000 1582 6047 13 37 240 794 788 706 688 303 650 430 169 338 682 474 1302 5726 7 260 364 676 429 829 593 393 3093 4633 10 445 696 872 473 722 581 431 839 242 865 6787 9528 14 939 408 814 967 129 419 875 974 27 389 491 494 733 621 547 3719 3 455 848 85 1166 3270 4 94 733 98 494 4811 8394 8 376 118 35...
output:
22 140 290 432 530 646 764 914 1059 1175 1335 1520 1737 1946 2131 2348 2584 2835 3131 3447 3793 4128 4379 4675 4991 5337 5697 5972 6268 6579 6895 7241 7611 7994 8372 8668 8979 9295 9641 10011 10394 10805 11224 11648 12077 12542 13018 13496 14016 14538 15075 15619 16168 16733 17301 17883 18492 19110 ...
result:
ok 400 lines
Test #19:
score: 0
Accepted
time: 54ms
memory: 7952kb
input:
1000 4799 7745 30 436 356 499 156 778 681 131 927 970 850 637 750 130 995 343 469 409 144 193 903 361 546 519 542 431 940 259 396 2 674 4405 5085 38 56 476 808 463 915 269 228 548 375 986 445 274 431 310 93 819 995 295 618 437 48 390 75 297 189 396 279 826 539 347 862 580 668 899 643 620 460 681 739...
output:
83 334 417 542 713 895 1157 1352 1614 1927 2215 2413 2675 2988 3276 3589 3947 4260 4593 4963 5339 5745 6168 6594 7052 7626 8141 8599 9076 9650 10165 10623 11126 11700 12271 12843 13417 13992 14603 15245 15910 16589 17227 17869 18520 19185 19864 20511 21162 21827 22506 23188 23857 24536 25223 25911 2...
result:
ok 320 lines
Test #20:
score: 0
Accepted
time: 71ms
memory: 7956kb
input:
1000 5276 9319 2 369 437 485 8427 6 762 890 744 913 131 814 2892 7100 6 155 159 257 24 208 945 382 4388 4 201 717 401 282 6874 9899 4 635 214 649 382 658 1765 7 168 516 818 643 14 143 546 3348 4656 5 154 686 977 469 791 5365 5689 3 258 161 621 569 1513 3 831 643 728 399 9290 1 753 1360 7246 6 866 59...
output:
409 590 999 1345 1754 2210 2619 3216 3625 4139 4899 5413 5927 6687 7216 7775 8534 9064 9681 10382 10999 11759 12491 13108 13868 14676 15486 16296 17106 17993 18867 19754 20703 21614 22501 23450 24417 25366 26385 27334 28330 29362 30319 31315 32347 33384 34429 35475 36528 37574 38620 39705 40751 4186...
result:
ok 522 lines
Extra Test:
score: 0
Extra Test Passed