QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699977 | #6308. Magic | Idtwtei | ML | 0ms | 3852kb | C++14 | 1.6kb | 2024-11-02 11:26:50 | 2024-11-02 11:26:51 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void write(ll x){
if(x<0)x=-x,putchar('-');
if(x>9)write(x/10);
putchar('0'+x%10);
}
const ll N=10005,INF=1e9;
ll n,l[N],r[N],S,T,tag[N],d[N];
bitset<N>to[N];
bool bfs(){
queue<ll>q;
q.push(S);
rep(i,1,T)d[i]=0;
d[S]=1;
while(!q.empty()){
ll u=q.front();q.pop();
ll v=to[u]._Find_first();
while(v<=T){
if(!to[u][v])break;
if(!d[v]){
d[v]=d[u]+1;
q.push(v);
if(v==T)return 1;
}
ll nxt=to[u]._Find_next(v);
v=max(v+1,nxt);
}
}
return 0;
}
ll dinic(ll u,ll flow){
ll rst=flow;
if(u==T)return flow;
ll v=to[u]._Find_first();
while(v<=T){
if(!to[u][v])break;
if(d[v]==d[u]+1){
ll k=dinic(v,min(rst,1ll));
if(!k)d[v]=0;
else {
rst--;
to[u][v]=0,to[v][u]=1;
}
if(!rst)return flow;
}
ll nxt=to[u]._Find_next(v);
v=max(v+1,nxt);
}
return flow-rst;
}
ll runflow(){
ll res=0;
while(bfs())res+=dinic(S,INF);
return res;
}
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
n=read();
rep(i,1,n)l[i]=read(),r[i]=read(),tag[r[i]]=1;
S=n*2+1,T=n*2+2;
rep(i,1,n){
rep(j,1,n){
if(l[i]<l[j]&&l[j]<r[i]&&r[i]<r[j])to[l[j]][r[i]]=1;
}
}
rep(i,1,2*n){
if(!tag[i])to[S][i]=1;
else to[i][T]=1;
}
write(2*n-runflow());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Memory Limit Exceeded
input:
5000 7985 7987 42 46 1591 1593 407 410 6305 6306 1456 1457 5874 5875 7135 7137 7041 7046 6813 6815 8868 8871 665 666 4055 4056 9789 9796 7067 7068 4745 4746 5167 5171 1735 1737 2125 2128 1444 1447 1348 1352 6087 6090 1381 1384 1600 1601 5187 5190 2801 2802 8449 8450 9376 9377 4021 4024 2674 2676 490...
output:
8134