QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#352667 | #7762. 数据库 | ANIG | 0 | 0ms | 0kb | C++23 | 1.9kb | 2024-03-13 14:59:09 | 2024-03-13 14:59:10 |
answer
#include <bits/stdc++.h>
using namespace std;
const int M=4e4+5,N=5005,inf=1e18;
struct node{
int to,sm,val;
}p[M];
vector<int>e[M];
int idx=1,st,ed,d[M],lst[M],ls[M],res,n,m,k,ans,w[M],g[M],cnt,nxt[N][N],f[M];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
bitset<M>mk;
void add(int x,int y,int z,int val){
e[x].push_back(++idx);
p[idx]=(node){y,z,val};
e[y].push_back(++idx);
p[idx]=(node){x,0,-val};
}
bool SPFA(){
mk.reset();
memset(d,0x3f,sizeof(d));
d[st]=0;ls[st]=inf;
q.push({0,st});
while(q.size()){
int x=q.top().second;
q.pop();
if(mk[x])continue;
mk[x]=1;
for(int i=0;i<e[x].size();i++){
int v=e[x][i],c=p[v].to;
if(!p[v].sm)continue;
if(d[c]>d[x]+p[v].val+f[x]-f[c]){
d[c]=d[x]+p[v].val+f[x]-f[c];
lst[c]=v;
ls[c]=min(ls[x],p[v].sm);
q.push({d[c],c});
}
}
}
if(d[ed]>1e18)return 0;
return 1;
}
void solve(){
int x=ed,t=ls[ed];
res+=(d[ed]+f[ed]-f[st])*t;ans+=t;
while(x!=st){
p[lst[x]].sm-=t;p[lst[x]^1].sm+=t;
x=p[lst[x]^1].to;
}
for(int i=1;i<=ed;i++)f[i]+=d[i];
}
void Solve(){
while(SPFA())solve();
}
signed main(){
cin>>n>>k>>m;
for(int i=1;i<=n;i++)cin>>w[i];
for(int i=1;i<=m;i++)cin>>g[i];
for(int i=1;i<=n;i++)nxt[m][i]=m+1;
for(int i=m-1;i>=0;i--){
for(int j=1;j<=n;j++)nxt[i][j]=nxt[i+1][j];
nxt[i][g[i+1]]=i+1;
}
for(int i=1;i<=m;i++){
add(i+m,i,1,w[g[i]]);
if(i!=m)add(i+1,nxt[i][g[i]]+m,1,0);
}
ed=2*m+1;st=2*m+2;
for(int i=1;i<=n;i++)add(st,nxt[0][i]+m,1,0);
for(int i=2;i<=m;i++)add(i-1,i,k,0);
add(m,ed,k,0);
Solve();
cout<<res;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
10 3 5000 23077 34848 88221 8067 83132 62621 41320 69146 32971 27594 2 7 5 3 9 6 1 9 4 8 1 8 8 3 6 9 1 7 5 5 6 8 1 3 10 6 8 7 10 2 1 2 6 7 5 5 9 5 7 10 10 6 6 7 2 4 3 1 10 10 5 1 1 6 1 2 8 9 2 5 10 1 10 7 5 5 10 5 2 5 6 10 9 5 6 3 5 3 6 5 7 4 1 5 8 1 1 9 7 1 1 2 1 8 6 2 9 8 4 2 5 4 5 2 10 4 3 6 9 7 ...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #4:
score: 0
Time Limit Exceeded
input:
10 2 5000 65644 5214 85000 40719 98071 56616 35404 16019 96748 89032 5 9 6 1 3 6 8 10 2 9 1 10 5 9 9 9 2 7 7 7 7 10 5 1 3 10 4 2 5 5 2 8 3 2 1 3 3 6 2 4 5 5 2 5 2 3 4 2 10 1 4 6 10 9 6 4 9 10 5 3 9 7 7 2 1 9 5 8 8 4 8 8 4 5 6 1 3 4 8 10 4 3 6 6 9 2 5 2 8 5 10 4 7 10 3 9 3 2 9 3 10 7 1 3 9 9 3 5 1 3 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
input:
5000 15 400 34145 93322 29976 7963 53362 50640 10859 94528 13329 49980 18826 50286 60155 79748 73253 18329 5216 83079 48220 98825 46592 76855 14037 19859 80960 4461 377 70496 28092 99806 5355 27013 92051 95231 65553 32365 3862 89764 86063 93033 12754 68996 38965 52942 69948 34370 3023 52079 16066 57...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #10:
score: 0
Time Limit Exceeded
input:
10 5 1000 86764 81108 88408 93029 87155 18790 28170 29349 81866 77109 8 7 10 7 2 7 1 8 4 10 9 10 4 1 7 1 9 9 1 6 6 1 9 6 7 1 8 10 1 7 9 1 1 9 7 10 8 5 5 1 2 3 10 6 2 6 2 6 1 2 7 8 5 6 10 2 9 8 2 6 8 5 10 8 1 10 4 6 5 6 3 8 1 3 5 2 2 7 2 4 5 5 8 2 4 1 3 6 8 2 2 3 1 8 1 5 8 6 9 7 7 3 7 9 8 9 9 7 5 3 6...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%