QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360244 | #6308. Magic | xlwang | TL | 0ms | 3636kb | C++14 | 2.2kb | 2024-03-21 15:55:58 | 2024-03-21 15:56:00 |
Judging History
answer
#include<bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define randfind(l,r) (rnd()%((r)-(l)+1)+(l))
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
//inline void init(){
// int t=read();
// while(t--) work();
//}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int Maxn=5e3+10;
bitset<Maxn> vc[Maxn];
int n,l[Maxn],r[Maxn];
int ans;
inline void init(){
n=read();
fr(i,1,n) l[i]=read(),r[i]=read();
}
int a[Maxn],b[Maxn];
bitset<Maxn> vis;
int mat[Maxn];
inline int bfs(int x){
queue<int> q;
int lst,fir=x;
vis.reset();
q.push(x);
lst=-1;
while(!q.empty() && lst==-1){
int tp=q.front();q.pop();
// cout<<"*"<<x<<' '<<tp<<endl;
auto tmp=(vc[tp]&(~vis));
for(int y=tmp._Find_first();y<=n;y=tmp._Find_next(y)){
// cerr<<y<<endl;
if(vis[y]) continue;vis[y]=1;
if(!mat[y]){mat[y]=tp;lst=tp;break;}
int tot=mat[y];
a[tot]=tp,b[tot]=y,q.push(y);
}
}
if(lst==-1) return 0;
// cout<<lst<<endl;
// fr(i,1,n) cout<<a[i]<<' '<<b[i]<<endl;
for(int i=lst;i!=fir;i=a[i]){
mat[b[i]]=a[i];
// cout<<i<<endl;
}
return 1;
}
inline void work(){
ans=2*n;
fr(i,1,n) fr(j,1,n){
if(i==j) continue;
if(l[i]<l[j] && l[j]<r[i] && r[i]<r[j]){
vc[i][j]=1;
// cout<<i<<' '<<j<<endl;
}
}
fr(i,1,n) if(bfs(i)) --ans;
writeln(ans);
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Time 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...