QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106379#6308. MagiczhouhuanyiRE 0ms0kbC++113.2kb2023-05-17 15:47:012023-05-17 15:47:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-17 15:47:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-17 15:47:01]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<bitset>
#define N 10002
#define M 5001
#define inf 1e9
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
struct reads
{
    int l,r;
    bool operator < (const reads &t)const
    {
	return l<t.l;
    }
};
reads st[N+1];
int n,s,t,ans,dque[N+1],sl,sr,leng,depth[N+1],l[N+1],r[N+1],p[N+1],tong1[N+1],num1[N+1],length1,tong2[N+1],num2[N+1],length2,len=1;
bool cl[N+1];
bitset<M+1>B[N+1];
bitset<M+1>vis[N+1];
bitset<M+1>used1;
bitset<M+1>used2;
bitset<M+1>S;
bool cmp(int x,int y)
{
    return depth[x]<depth[y];
}
void add(int x,int y)
{
    if (!cl[x]) B[x][num2[y]]=1;
    else B[x][num1[y]]=1;
    return;
}
bool bfs()
{
    int top;
    for (int i=s;i<=t;++i) depth[i]=0;
    used1.set(),used2.set(),dque[sl=sr=1]=top,used1[num1[s]]=0,depth[s]=1;
    while (sl<=sr)
    {
	top=dque[sl],sl++;
	if (!cl[top])
	{
	    S=used2&B[top];
	    for (int i=S._Find_first();i!=S.size();i=S._Find_next(i)) depth[tong2[i]]=depth[top]+1,used2[i]=0,dque[++sr]=tong2[i];
	}
	else
	{
	    S=used1&B[top];
	    for (int i=S._Find_first();i!=S.size();i=S._Find_next(i)) depth[tong1[i]]=depth[top]+1,used1[i]=0,dque[++sr]=tong1[i];
	}
    }
    return !used2[num2[t]];
}
int dinic(int x,int flow)
{
    if (x==t) return flow;
    int k,y;
    while (1)
    {
	if (!cl[x])
	{
	    S=B[x]&vis[x],y=S._Find_first();
	    if (y==S.size()) return 0;
	    k=dinic(tong2[y],1);
	    if (k)
	    {
		B[x][y]=0,B[tong2[y]][num1[x]]=1;
		return 1;
	    }
	    else vis[x][y]=0;
	}
	else
	{
	    S=B[x]&vis[x],y=S._Find_first();
	    if (y==S.size()) return 0;
	    k=dinic(tong1[y],1);
	    if (k)
	    {
		B[x][y]=0,B[tong1[y]][num2[x]]=1;
		return 1;
	    }
	    else vis[x][y]=0;
	}
    }
    return 0;
}
int main()
{
    int flow;
    n=read(),ans=n<<1,s=0,t=(n<<1)+1;
    for (int i=1;i<=n;++i) st[i].l=read(),st[i].r=read();
    sort(st+1,st+n+1);
    tong1[++length1]=s,num1[s]=length1,cl[s]=0;
    for (int i=1;i<=n;++i) tong1[++length1]=i+n,num1[i+n]=length1,cl[i]=0;
    tong2[++length2]=t,num2[t]=length2,cl[t]=1;
    for (int i=1;i<=n;++i) tong2[++length2]=i,num2[i]=length2,cl[i]=1;
    for (int i=1;i<=n;++i) add(s,i),add(i+n,t);
    for (int i=1;i<=n;++i)
	for (int j=i+1;j<=n;++j)
	    if (st[i].l<st[j].l&&st[j].l<st[i].r&&st[i].r<st[j].r)
		add(i,j+n);
    while (bfs())
    {
	for (int i=s;i<=t;++i) p[i]=i;
	sort(p,p+t,cmp),used1.reset(),used2.reset();
	for (int i=s;i<=t;++i) r[depth[p[i]]]=i;
	for (int i=t;i>=s;--i) l[depth[p[i]]]=i;
	for (int i=0;i<=t;++i)
	{
	    if (i+1<=t)
	    {
		for (int j=l[i+1];j<=r[i+1];++j)
		{
		    if (!cl[p[j]]) used1[num1[p[j]]]=1;
		    else used2[num2[p[j]]]=1;
		}
	    }
	    for (int j=l[i];j<=r[i];++j)
	    {
		if (!cl[p[j]]) vis[p[j]]=used2;
		else vis[p[j]]=used1;
	    }
	    if (i+1<=t)
	    {
		for (int j=l[i+1];j<=r[i+1];++j)
		{
		    if (!cl[p[j]]) used1[num1[p[j]]]=0;
		    else used2[num2[p[j]]]=0;
		}
	    }
	}
	while (flow=dinic(s,inf)) ans-=flow;
    }
    printf("%d\n",ans);
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

5
2 3
6 7
1 9
5 10
4 8

output:


result: