QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397749 | #6308. Magic | Lynkcat | RE | 0ms | 3640kb | C++17 | 1.4kb | 2024-04-24 16:38:07 | 2024-04-24 16:38:08 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) (int)((x).size())
//#define int ll
//#define N
using namespace std;
const int N=5005;
int n,l[N],r[N];
int col[N];
int lst[N];
int mth[N];
bitset<5005>f[5005];
void bfs(int k)
{
queue<int>q;
bitset<5005>ex;
for (int i=1;i<=n;i++) ex[i]=1,lst[i]=0;
q.push(k);
while (!q.empty())
{
int u=q.front();q.pop();
bitset<5005>now=(ex&f[u]);
int v=now._Find_first();
while (v<=n)
{
if (!mth[v])
{
int o=u;
while (1)
{
int lt=mth[u];
mth[u]=v;
mth[v]=u;
if (lt==0) return;
u=lst[u];
v=lt;
}
}
else
{
ex[v]=0;
now[v]=0;
lst[mth[v]]=u;
q.push(mth[v]);
}
v=now._Find_first();
}
}
}
void BellaKira()
{
cin>>n;
for (int i=1;i<=n;i++)
cin>>l[i]>>r[i],col[l[i]]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (r[i]>l[j]&&r[i]<r[j]&&l[i]<l[j])
f[r[i]][l[j]]=1,f[l[j]][r[i]]=1;
n*=2;
for (int i=1;i<=n;i++)
if (!mth[i]&&col[i]) bfs(i);
int ans=n;
for (int i=1;i<=n;i++)
if (col[i]&&mth[i]) ans--;
cout<<ans<<'\n';
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
while (T--)
{
BellaKira();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Runtime Error
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...