QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#28372 | #1876. MIPT: Connecting People | guobo | AC ✓ | 293ms | 344096kb | C++14 | 3.5kb | 2022-04-13 21:11:00 | 2022-04-29 09:42:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=66,maxm=3333,mod=998244353,INF=1e9;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
char ch=getchar();int x=0,f=0;
while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
inline int qpow(int a,int b){
int ans=1;
for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
return ans;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
void clear(){
}
int n,a[maxn],v1,v2[maxn],m,L[maxn],R[maxn],lll[maxm],rrr[maxm],s[maxn];
ll F[maxn][maxn][maxm],G[maxn][maxn][maxm],H[maxn][maxn][maxm];
// all,down,up
inline ll& f(int l,int r,int i,int j){return F[l][r][L[i]+j];}
inline ll& g(int l,int r,int i,int j){return G[l][r][L[i]+j];}
inline ll& h(int l,int r,int i,int j){return H[l][r][L[i]+j];}
inline int sz(int l,int r){return l>r?0:s[r]-s[l-1];}
inline int szf(int l,int r,int i,int j){return j>a[i] || j<1?0:sz(l,r);}
inline int szg(int l,int r,int i,int j){return j>a[i] || j<1?0:sz(l,r)-a[i]+j;}
inline int szh(int l,int r,int i,int j){return j>a[i] || j<1?0:sz(l,r)+a[i]-j+1;}
inline int& lft(int i,int j){return lll[L[i]+j];}
inline int& rig(int i,int j){return rrr[L[i]+j];}
inline ll func(int c,int x){return 1ll*x*(m-x)*c;}
inline void chkmin(ll &x,ll y){if(y<x) x=y;}
void mian(){
MEM(F,0x3f);MEM(G,0x3f);MEM(H,0x3f);
n=read();v1=read();
FOR(i,1,n){
a[i]=read();v2[i]=read();
s[i]=s[i-1]+a[i];
L[i]=R[i-1]+1;R[i]=L[i]+a[i]+1;
m+=a[i];
}
FOR(i,1,n){
ll sum=0;
FOR(j,1,a[i]){
FOR(k,1,n+1) h(k,k-1,i,a[i]-j+1)=sum;
sum=sum+func(v2[i],j);
}
FOR(j,1,a[i]){
ROF(k,i-1,1) if(a[k]>=j){lft(i,j)=k;break;}
rig(i,j)=n+1;
FOR(k,i+1,n) if(a[k]>=j){rig(i,j)=k;break;}
}
g(i,i,i,0)=0;
FOR(k,1,n+1) h(k,k-1,i,a[i]+1)=0;
}
ROF(l,n,1) FOR(r,l,n){
FOR(i,l,r) FOR(j,1,a[i]){
int prv=lft(i,j),nxt=rig(i,j);
chkmin(g(l,r,i,j),g(l,r,i,j-1)+func(v2[i],szg(l,r,i,j-1)));
if(prv>=l){
FOR(k,prv,i-1) chkmin(g(l,r,i,j),g(k+1,r,i,j-1)+f(l,k,prv,j)+func(v2[i],szg(k+1,r,i,j-1))+func(v1,szf(l,k,prv,j)));
}
if(nxt<=r){
FOR(k,i+1,nxt) chkmin(g(l,r,i,j),g(l,k-1,i,j-1)+f(k,r,nxt,j)+func(v2[i],szg(l,k-1,i,j-1))+func(v1,szf(k,r,nxt,j)));
if(prv>=l){
FOR(k,prv,i-1) FOR(kk,i+1,nxt) chkmin(g(l,r,i,j),g(k+1,kk-1,i,j-1)+f(l,k,prv,j)+f(kk,r,nxt,j)+func(v2[i],szg(k+1,kk-1,i,j-1))+func(v1,szf(l,k,prv,j))+func(v1,szf(kk,r,nxt,j)));
}
}
}
FOR(i,l,r){
FOR(j,1,a[i]) FOR(k,l-1,i-1) chkmin(f(l,r,i,j),g(k+1,r,i,j)+h(l,k,i,j));
FOR(j,1,a[i]) FOR(k,i+1,r+1) chkmin(f(l,r,i,j),g(l,k-1,i,j)+h(k,r,i,j));
}
FOR(i,1,l-1) ROF(j,a[i],1){
int nxt=rig(i,j);
chkmin(h(l,r,i,j),h(l,r,i,j+1)+func(v2[i],szh(l,r,i,j+1)));
if(nxt>=l && nxt<=r) FOR(k,nxt,r) chkmin(h(l,r,i,j),h(k+1,r,i,j+1)+f(l,k,nxt,j)+func(v2[i],szh(k+1,r,i,j+1))+func(v1,szf(l,k,nxt,j)));
}
FOR(i,r+1,n) ROF(j,a[i],1){
int prv=lft(i,j);
chkmin(h(l,r,i,j),h(l,r,i,j+1)+func(v2[i],szh(l,r,i,j+1)));
if(prv>=l && prv<=r) FOR(k,l,prv) chkmin(h(l,r,i,j),h(l,k-1,i,j+1)+f(k,r,prv,j)+func(v2[i],szh(l,k-1,i,j+1))+func(v1,szf(k,r,prv,j)));
}
}
printf("%lld\n",f(1,n,1,a[1]));
}
int main(){
int T=1;
// T=read();
while(T--) mian();
}
詳細信息
Test #1:
score: 100
Accepted
time: 68ms
memory: 343988kb
input:
1 1 5 1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 60ms
memory: 343952kb
input:
2 1 3 3 3 2
output:
59
result:
ok answer is '59'
Test #3:
score: 0
Accepted
time: 71ms
memory: 343948kb
input:
5 1000 10 1 1 1 7 1 3 1 8 1
output:
460314
result:
ok answer is '460314'
Test #4:
score: 0
Accepted
time: 40ms
memory: 343952kb
input:
5 1 10 1000 1 1000 7 1000 3 1000 8 1000
output:
1626464
result:
ok answer is '1626464'
Test #5:
score: 0
Accepted
time: 44ms
memory: 343952kb
input:
1 414619 100 498997
output:
83157850050
result:
ok answer is '83157850050'
Test #6:
score: 0
Accepted
time: 40ms
memory: 344024kb
input:
1 144052 3000 309889
output:
1394500345055500
result:
ok answer is '1394500345055500'
Test #7:
score: 0
Accepted
time: 87ms
memory: 343948kb
input:
2 76800 65 647554 35 185123
output:
60514170820
result:
ok answer is '60514170820'
Test #8:
score: 0
Accepted
time: 67ms
memory: 343976kb
input:
2 256220 1963 311961 1037 530722
output:
1137091926771735
result:
ok answer is '1137091926771735'
Test #9:
score: 0
Accepted
time: 59ms
memory: 344088kb
input:
3 706278 31 369111 56 923899 13 865399
output:
83196440515
result:
ok answer is '83196440515'
Test #10:
score: 0
Accepted
time: 52ms
memory: 344036kb
input:
10 26988 2 524303 2 155871 5 529858 5 738490 6 611743 9 190337 11 321000 16 768996 19 139086 25 129074
output:
12630754247
result:
ok answer is '12630754247'
Test #11:
score: 0
Accepted
time: 74ms
memory: 343948kb
input:
15 493819 1 60941 1 504136 4 823213 4 337706 6 752723 8 981650 8 417667 10 82528 15 749793 15 64009 20 505391 24 509759 25 368532 25 570000 34 891167
output:
161899980099
result:
ok answer is '161899980099'
Test #12:
score: 0
Accepted
time: 48ms
memory: 343972kb
input:
20 774273 57 98503 54 987715 28 497327 28 322838 24 602203 19 826069 17 54268 17 245979 12 10461 9 278770 8 59419 5 919077 5 914772 4 215123 4 328862 3 793413 2 860603 2 599363 1 629514 1 228067
output:
540329602056
result:
ok answer is '540329602056'
Test #13:
score: 0
Accepted
time: 53ms
memory: 343972kb
input:
30 700778 22 619045 19 292419 16 617155 15 846390 14 239675 11 487485 10 889944 9 564266 8 825369 5 6740 3 172641 2 200875 2 400754 1 19725 1 353498 1 291351 1 268204 2 557821 2 160819 2 200542 3 658532 5 25106 5 94162 7 373318 15 62374 17 647947 17 862222 19 278058 26 433781 40 600187
output:
401215134717
result:
ok answer is '401215134717'
Test #14:
score: 0
Accepted
time: 41ms
memory: 343968kb
input:
35 722567 1 200872 1 514068 1 10665 4 374744 4 299692 5 866972 6 904423 10 469940 11 459022 11 22654 14 883138 15 563323 16 338439 16 460833 18 417530 19 391982 20 665025 27 566400 28 936516 32 335843 34 564059 35 380715 36 155911 41 982212 42 583398 43 730823 44 656034 49 642702 49 399146 65 227978...
output:
24925315532374
result:
ok answer is '24925315532374'
Test #15:
score: 0
Accepted
time: 83ms
memory: 344012kb
input:
40 859188 1 127057 3 421607 3 258208 4 462623 5 884519 7 326001 7 952440 10 234729 11 58711 12 534179 15 249916 16 21348 20 936791 20 615047 20 291731 26 660955 28 956574 29 975947 30 972009 31 690943 32 689772 42 162754 43 668780 44 786533 44 115328 46 860514 49 779024 51 647235 56 780064 58 660932...
output:
45832150212339
result:
ok answer is '45832150212339'
Test #16:
score: 0
Accepted
time: 109ms
memory: 344032kb
input:
45 681930 17 596186 47 231915 75 202526 82 294928 145 985178 121 252917 105 775694 82 802120 80 232962 76 771486 69 949527 60 180712 51 92888 49 646820 41 611477 40 328789 40 278962 39 93237 33 247996 32 232042 29 521340 29 92600 29 599952 26 299255 24 616182 24 185925 23 657195 21 286077 20 829940 ...
output:
39420897223318
result:
ok answer is '39420897223318'
Test #17:
score: 0
Accepted
time: 105ms
memory: 344012kb
input:
50 95214 120 539289 93 685661 88 431030 68 61430 62 197898 61 326417 55 81099 47 514463 46 820102 45 867988 41 80326 40 528879 38 440444 35 354615 33 789276 31 801670 31 557636 25 876106 25 265315 24 305354 23 954328 23 550375 22 278809 13 486948 12 943638 12 36968 12 201757 11 335681 10 575487 9 55...
output:
18366752576638
result:
ok answer is '18366752576638'
Test #18:
score: 0
Accepted
time: 48ms
memory: 344016kb
input:
30 640639 91 280493 53 947710 46 831222 46 163409 42 997956 39 522732 38 948925 31 461777 19 658490 15 83150 2 819526 2 625759 2 718821 3 64080 8 716695 8 566438 14 698013 14 896512 15 399804 18 190072 18 215168 20 369742 24 825603 28 610055 35 447535 54 69650 79 314176 79 886189 81 147854 87 414598
output:
9169451983590
result:
ok answer is '9169451983590'
Test #19:
score: 0
Accepted
time: 52ms
memory: 344024kb
input:
20 606776 83 41819 4 466421 12 805260 2 653965 1 931711 5 241476 20 201338 9 188845 34 394803 156 948091 21 612355 76 929434 148 195290 169 539644 58 977331 47 237873 100 350856 149 868155 151 232391 93 603553
output:
33506308793328
result:
ok answer is '33506308793328'
Test #20:
score: 0
Accepted
time: 76ms
memory: 344048kb
input:
30 223727 12 252140 6 349138 92 466904 139 722082 38 362824 15 595419 9 584282 3 470727 39 845558 63 378120 10 359927 15 248412 45 174800 127 901793 103 29037 14 559131 19 678872 36 370933 142 765470 94 543813 10 699506 13 513620 14 737104 77 878940 97 407077 7 769427 1 300525 26 765224 65 348701 1 ...
output:
28208163341309
result:
ok answer is '28208163341309'
Test #21:
score: 0
Accepted
time: 92ms
memory: 343932kb
input:
60 265406 1 756550 1 429646 1 390955 1 208173 1 203516 2 838949 2 381413 2 276474 2 136508 2 373655 2 401746 3 687626 3 418700 3 325297 3 257521 3 598901 3 103748 3 74743 4 602261 4 390729 4 497171 4 301088 4 937958 4 795143 5 929531 5 561749 5 804703 6 40610 6 193937 7 429046 7 31249 7 909379 7 602...
output:
1471812853452
result:
ok answer is '1471812853452'
Test #22:
score: 0
Accepted
time: 264ms
memory: 343976kb
input:
60 346466 1 475541 1 909687 1 967904 2 11171 2 270489 3 322884 3 207756 7 653301 7 131127 8 732628 8 355892 10 951426 10 555421 13 984871 13 856555 13 103416 13 892832 14 29820 16 445222 21 339659 21 748344 23 598297 24 164673 25 947250 27 170434 30 321286 31 923320 33 500200 33 695037 33 669266 33 ...
output:
66837998781548
result:
ok answer is '66837998781548'
Test #23:
score: 0
Accepted
time: 190ms
memory: 344016kb
input:
60 73484 1 57880 1 351733 1 82619 2 960983 3 899700 4 298413 5 274531 6 12142 13 179072 14 417833 21 991463 21 263717 24 511061 33 624201 34 759667 42 941182 42 373908 50 365970 54 624763 63 909535 80 858591 77 146796 77 230769 44 405970 42 988765 42 167266 35 960336 33 752198 31 80314 26 516005 25 ...
output:
10094984905612
result:
ok answer is '10094984905612'
Test #24:
score: 0
Accepted
time: 199ms
memory: 344096kb
input:
60 226757 160 683460 159 593427 151 942934 85 716142 79 291787 78 720545 62 28770 49 966755 46 479002 42 314007 41 876836 39 421418 37 234265 36 868575 36 12654 34 213799 33 620325 33 97653 31 8134 25 665234 24 600655 24 149613 24 113448 23 372853 23 795162 22 533355 21 855042 20 384882 17 905281 16...
output:
51467901727786
result:
ok answer is '51467901727786'
Test #25:
score: 0
Accepted
time: 259ms
memory: 343980kb
input:
60 771670 47 2985 3 320750 10 96990 65 5490 22 11993 2 64893 26 29645 17 16758 18 52512 2 282603 19 28346 36 22625 16 59836 2 214828 10 81193 10 34494 31 9661 2 9305 26 5511 35 662 6 91533 2 345069 27 27510 43 21305 51 15018 3 247323 20 19624 17 53193 27 19045 1 752431 10 36221 89 9525 13 17576 1 83...
output:
3340713056515
result:
ok answer is '3340713056515'
Test #26:
score: 0
Accepted
time: 293ms
memory: 343940kb
input:
60 449855 1 289075 64 11476 3 278185 4 215761 2 211290 14 11818 1 324724 64 10234 12 70719 3 215123 2 306920 59 14017 32 26727 36 16948 1 253336 4 116572 75 8907 71 10708 54 7621 1 536933 8 61883 7 101819 79 9981 31 13723 1 253370 1 593361 42 12161 95 4135 50 8984 4 174789 17 36489 53 17931 70 4116 ...
output:
2593239136575
result:
ok answer is '2593239136575'
Test #27:
score: 0
Accepted
time: 198ms
memory: 343968kb
input:
60 1000000 32 591475 92 46411 53 892519 46 337562 1 135221 10 358346 16 858774 22 593249 1 79108 7 931579 14 411440 27 992221 19 441913 8 200138 6 957978 9 174357 3 4195 4 6135 66 702123 48 237858 11 748996 21 829717 25 873840 23 655794 6 848212 1 428365 24 434091 23 702662 4 527997 5 374425 19 9525...
output:
11357940055834
result:
ok answer is '11357940055834'