QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411001 | #8131. Filesystem | JohnAlfnov | WA | 1ms | 7844kb | C++20 | 1.9kb | 2024-05-14 20:00:34 | 2024-05-14 20:00:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,S,T;
int hd[100005],nxt[300005],c[300005],dy[300005],tot=1;
int cur[100005],l[100005];
void addedge(int u,int v,int w){
nxt[++tot]=hd[u],hd[u]=tot;
c[tot]=w,dy[tot]=v;
}
bool getc(){
for(int i=1;i<=n;++i)l[i]=1e9,cur[i]=hd[i];
l[S]=0;
queue<int>q;
q.emplace(S);
while(q.size()){
int x=q.front();
q.pop();
for(int i=hd[x];i;i=nxt[i]){
if(!c[i])continue;
int cu=dy[i];
if(l[cu]>l[x]+1){
l[cu]=l[x]+1;
q.emplace(cu);
}
}
}
return l[T]<1e9;
}
long long ans;
int dinic(int x,int rl){
if(x==T){
ans+=rl;
return rl;
}
int rr=rl;
for(int i=cur[x];i;i=nxt[i]){
cur[x]=i;
if(!c[i])continue;
int cu=dy[i];
if(l[cu]!=l[x]+1)continue;
int zz=dinic(cu,min(rr,c[i]));
c[i]-=zz,c[i^1]+=zz;
rr-=zz;
if(!rr)break;
}
return rl-rr;
}
int u[1005],uu[1005],p[1005],pp[1005],d1[1005],d2[1005];
int main(){
int TT;
scanf("%d",&TT);
int tt=0;
while(TT--){
++tt;
int N,K;
scanf("%d%d",&N,&K);
for(int i=1;i<=K;++i)scanf("%d",&u[i]),uu[u[i]]=tt;
for(int i=1;i<=N;++i)scanf("%d",&p[i]),pp[p[i]]=i;
n=1+N+N+1,S=1,T=n;
for(int i=1;i<=n;++i)hd[i]=0;
for(int i=1;i<=tot;++i)dy[i]=c[i]=nxt[i]=0;
tot=1;
for(int i=1;i<=N;++i)d1[i]=d2[i]=0;
for(int i=1;i<=N;++i)if(uu[i]==tt){
if(uu[i-1]!=tt){
++d1[i];
}else{
addedge(1+i,1+N+i-1,1);addedge(1+N+i-1,1+i,0);
}
}
for(int i=1;i<=N;++i)if(uu[pp[i]]==tt){
int x=pp[i],y=pp[i-1];
if(uu[y]!=tt){
++d2[i];
}else{
addedge(1+y,1+N+x,1);addedge(1+N+x,1+y,0);
}
}
long long he=0;
for(int i=1;i<=N;++i)if(uu[i]==tt){
int mm=1e9;
he+=mm;
addedge(S,1+i,mm+d2[i]);addedge(1+i,S,0);
addedge(1+i,1+N+i,2*mm);
addedge(1+N+i,T,mm+d1[i]);addedge(T,1+N+i,0);
}
ans=0;
while(getc())dinic(S,INT_MAX);
printf("%lld\n",ans-he);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5792kb
input:
2 12 8 2 5 8 3 4 10 12 1 10 5 8 6 4 7 2 3 11 12 1 9 8 4 1 3 5 7 1 4 5 8 7 6 3 2
output:
3 4
result:
ok 2 number(s): "3 4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7844kb
input:
100 10 3 10 5 2 2 4 9 8 7 3 1 5 10 6 10 3 8 1 10 8 4 3 7 1 2 9 5 6 10 10 3 6 5 2 8 7 6 4 2 10 1 3 5 9 10 3 5 8 4 10 4 5 7 8 9 1 2 3 6 10 3 8 4 10 10 6 9 2 8 7 1 4 3 5 10 3 9 8 1 8 5 6 10 2 4 1 7 9 3 10 3 5 4 1 7 5 8 4 3 6 9 10 2 1 10 3 2 4 3 6 7 3 9 1 2 5 8 4 10 10 3 9 5 3 6 10 7 4 9 3 1 8 5 2 10 3 ...
output:
0 2 1 0 1 0 0 1 2 1 0 1 0 0 1 1 1 2 0 2 1 2 0 1 2 1 0 1 1 1 1 1 0 2 1 2 2 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 0 2 0 1 2 1 1 1 1 0 1 1 0 1 0 1 0 1 1 0 1 1 1 0 0 1 3 0 1 2 0 0 0 1 0 0 0 0 0 0 1 2 2 0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'