QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308950 | #8131. Filesystem | ucup_team_qiuly# | WA | 1ms | 3956kb | C++17 | 1.6kb | 2024-01-20 13:57:32 | 2024-01-20 13:57:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e6+5,INF=1e9,D=1e5;
int Case,n,n1,tmp,a[N],b[N];
int cntE,hd[N];struct Edge {int v,w,nxt;}e[M];
int cntV,S,T,dst[N],cur[N],q[N];
void addE(int u,int v,int w,int w1=0)
{
e[cntE]=(Edge) {v,w,hd[u]};hd[u]=cntE++;
e[cntE]=(Edge) {u,w1,hd[v]};hd[v]=cntE++;
}
bool bfs(int S,int T)
{
copy(hd+1,hd+cntV+1,cur+1);fill(dst+1,dst+cntV+1,-1);
dst[S]=0;q[0]=2;q[1]=1;q[++q[1]]=S;
while(q[0]<=q[1])
{
int u=q[q[0]++];
for(int i=hd[u],v,w;~i;i=e[i].nxt)
{
v=e[i].v;w=e[i].w;
if(w && dst[v]==-1)
{dst[v]=dst[u]+1;q[++q[1]]=v;if(v==T) return 1;}
}
}return 0;
}
int dfs(int u,int T,int nw)
{
if(u==T) return nw;int flw=0;
for(int i=cur[u],v,w,t;~i;i=e[i].nxt)
{
v=e[i].v;w=e[i].w;cur[u]=i;
if(w && dst[u]+1==dst[v] && (t=dfs(v,T,min(nw,w))))
{nw-=t;flw+=t;e[i].w-=t;e[i^1].w+=t;if(!nw) break;}
}if(!flw) dst[u]=-1;return flw;
}
int Dinic(int S,int T)
{int flw=0;while(bfs(S,T)) flw+=dfs(S,T,INF);return flw;}
void ins1(int u,int v) {--tmp;addE(u,v,1,1);addE(S,u,1);addE(S,v,1);}
void ins2(int u,int v) {--tmp;addE(u,v,1,1);addE(u,T,1);addE(v,T,1);}
void slv()
{
scanf("%d %d",&n1,&n);S=n+1;T=cntV=n+2;tmp=n;
cntE=0;fill(hd+1,hd+cntV+1,-1);fill(a+1,a+n1+1,0);
for(int i=1,x;i<=n;++i) scanf("%d",&x),a[x]=1;
for(int i=1;i<=n1;++i) scanf("%d",&b[i]);
for(int i=1;i<=n;++i) addE(S,i,D),addE(i,T,D);
for(int i=1;i<n;++i) if(a[i] && a[i+1]) ins1(i,i+1);
for(int i=1;i<n;++i) if(a[b[i]] && a[b[i+1]]) ins2(b[i],b[i+1]);
printf("%d\n",tmp+(Dinic(S,T)-n*D)/2);
}
int main()
{
scanf("%d",&Case);
while(Case--) slv();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3956kb
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: 1ms
memory: 3884kb
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:
3 3 3 3 3 3 3 2 3 3 3 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 2 3 2 3 3 2 3 3 3 3 2 3 2 3 2 3 3 2 3 3 3 2 2 2 3 2 3 3 3 1 3 2 2 3 2 3 3 3 3 3 3 2 3 2 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 2 3 3 3 2 3 2
result:
wrong answer 1st numbers differ - expected: '2', found: '3'