QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#51355 | #1876. MIPT: Connecting People | tricyzhkx | WA | 12ms | 74212kb | C++14 | 2.2kb | 2022-10-02 11:06:31 | 2022-10-02 11:06:32 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70],sum[70],tv[70],id[70][3010],L[70][3010],R[70][3010];
ll f[3001][61][61],g[3001][61][61],h[3001][61][61],mnL[3001][61][61],mnR[3001][61][61];
void upd(ll &a,ll b){a>b?a=b:0;}
int main()
{
int n,th,tot=0;
cin>>n>>th;
for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&tv[i]),sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=a[i];j++)
id[i][j]=++tot;
for(int i=0;i<=tot;i++)
for(int j=1;j<=n;j++)
for(int k=j;k<=n;k++)
f[i][j][k]=g[i][j][k]=h[i][j][k]=mnL[i][j][k]=mnR[i][j][k]=1e18;
for(int i=1;i<=n;i++)
for(int j=1;j<=a[i];j++)
{
int p;
for(p=i-1;p && a[p]<j;p--);
L[i][j]=p;
for(p=i+1;p<=n && a[p]<j;p++);
R[i][j]=p;
}
auto calc=[&](ll w,int sz){return w*sz*(tot-sz);};
for(int l=1;l<=n+1;l++)
for(int i=1;i<=n;i++)
for(int j=a[i];j>=1;j--)
h[id[i][j]][l][l-1]=h[id[i][j+1]][l][l-1]+calc(tv[i],a[i]-j+1);
for(int l=n;l>=1;l--)
for(int r=l;r<=n;r++)
{
for(int i=l;i<=r;i++)
for(int j=1;j<=a[i];j++)
{
int pl=L[i][j],pr=R[i][j],k=id[i][j],kl=id[pl][j],kr=id[pr][j],k2=id[i][j-1];
auto G=[&](int l,int r){return k2?g[k2][l][r]:(l==i && r==i?0:1e18);};
for(int m=l-1;m<i;m++) upd(mnL[k][l][r],f[kl][l][m]+G(m+1,r));
for(int m=i;m<=r;m++) upd(mnR[k][l][r],G(l,m)+f[kr][m+1][r]);
for(int m=i;m<=r;m++) upd(g[k][l][r],mnL[k][l][m]+f[kr][m+1][r]);
g[k][l][r]+=calc(tv[i],sum[r]-sum[l-1]-a[i]+j);
k2=id[i][j+1];
for(int m=i;m<=r;m++) upd(f[k][l][r],mnL[k][l][m]+h[k2][m+1][r]);
for(int m=l-1;m<i;m++) upd(f[k][l][r],h[k2][l][m]+mnR[k][m+1][r]);
f[k][l][r]+=calc(th,sum[r]-sum[l-1]);
}
for(int i=1;i<l;i++)
for(int j=a[i];j>=1;j--)
{
int p=R[i][j],k=id[i][j],k1=id[p][j],k2=id[i][j+1];
for(int m=l-1;m<=r;m++) upd(h[k][l][r],f[k1][l][m]+h[k2][m+1][r]);
h[k][l][r]+=calc(tv[i],a[i]-j+1+sum[r]-sum[l-1]);
}
for(int i=r+1;i<=n;i++)
for(int j=a[i];j>=1;j--)
{
int p=L[i][j],k=id[i][j],k1=id[p][j],k2=id[i][j+1];
for(int m=l-1;m<=r;m++) upd(h[k][l][r],h[k2][l][m]+f[k1][m+1][r]);
h[k][l][r]+=calc(tv[i],a[i]-j+1+sum[r]-sum[l-1]);
}
}
cout<<f[id[1][a[1]]][1][n]<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 5848kb
input:
1 1 5 1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 3ms
memory: 5724kb
input:
2 1 3 3 3 2
output:
59
result:
ok answer is '59'
Test #3:
score: 0
Accepted
time: 0ms
memory: 6704kb
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: 0ms
memory: 6692kb
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: 2ms
memory: 7708kb
input:
1 414619 100 498997
output:
83157850050
result:
ok answer is '83157850050'
Test #6:
score: 0
Accepted
time: 4ms
memory: 67212kb
input:
1 144052 3000 309889
output:
1394500345055500
result:
ok answer is '1394500345055500'
Test #7:
score: 0
Accepted
time: 1ms
memory: 8128kb
input:
2 76800 65 647554 35 185123
output:
60514170820
result:
ok answer is '60514170820'
Test #8:
score: 0
Accepted
time: 3ms
memory: 74212kb
input:
2 256220 1963 311961 1037 530722
output:
1137091926771735
result:
ok answer is '1137091926771735'
Test #9:
score: 0
Accepted
time: 2ms
memory: 8028kb
input:
3 706278 31 369111 56 923899 13 865399
output:
83196440515
result:
ok answer is '83196440515'
Test #10:
score: 0
Accepted
time: 2ms
memory: 10064kb
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: 5ms
memory: 16836kb
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: 2ms
memory: 25216kb
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: -100
Wrong Answer
time: 12ms
memory: 33272kb
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:
401305585637
result:
wrong answer expected '401215134717', found '401305585637'