QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#24441 | #1876. MIPT: Connecting People | guobo | WA | 66ms | 344088kb | C++14 | 3.6kb | 2022-03-30 20:17:19 | 2022-04-30 05:40:11 |
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],wtf;
// 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-1];}
inline int& rig(int i,int j){return rrr[L[i]+j-1];}
inline ll func(int c,int x){return 1ll*x*(m-2*n-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]=m+1;R[i]=m+=a[i]+2;
}
FOR(i,1,n){
ll sum=0;
FOR(j,1,a[i]){
FOR(k,1,n+1) g(i,i,i,j)=h(k,k-1,i,a[i]-j+1)=sum;
f(i,i,i,j)=f(i,i,i,a[i]-j+1)=g(i,i,i,j)+h(1,0,i,j);
sum=sum+func(v2[i],j);
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+1,n){
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)));
}
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+1)+func(v2[i],szh(l,k,i,j+1)));
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+1)+func(v2[i],szh(k,r,i,j+1)));
}
}
printf("%lld\n",f(1,n,1,a[1]));
}
int main(){
int T=1;
// T=read();
while(T--) mian();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 343944kb
input:
1 1 5 1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 44ms
memory: 343952kb
input:
2 1 3 3 3 2
output:
59
result:
ok answer is '59'
Test #3:
score: 0
Accepted
time: 63ms
memory: 344016kb
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: 43ms
memory: 344000kb
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: 66ms
memory: 344012kb
input:
1 414619 100 498997
output:
83157850050
result:
ok answer is '83157850050'
Test #6:
score: 0
Accepted
time: 36ms
memory: 344032kb
input:
1 144052 3000 309889
output:
1394500345055500
result:
ok answer is '1394500345055500'
Test #7:
score: 0
Accepted
time: 48ms
memory: 343920kb
input:
2 76800 65 647554 35 185123
output:
60514170820
result:
ok answer is '60514170820'
Test #8:
score: 0
Accepted
time: 60ms
memory: 344024kb
input:
2 256220 1963 311961 1037 530722
output:
1137091926771735
result:
ok answer is '1137091926771735'
Test #9:
score: 0
Accepted
time: 35ms
memory: 344016kb
input:
3 706278 31 369111 56 923899 13 865399
output:
83196440515
result:
ok answer is '83196440515'
Test #10:
score: -100
Wrong Answer
time: 51ms
memory: 344088kb
input:
10 26988 2 524303 2 155871 5 529858 5 738490 6 611743 9 190337 11 321000 16 768996 19 139086 25 129074
output:
16131592862
result:
wrong answer expected '12630754247', found '16131592862'