QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537606 | #6308. Magic | chenxinyang2006 | WA | 1ms | 5872kb | C++20 | 3.2kb | 2024-08-30 16:35:53 | 2024-08-30 16:35:54 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n;
int a[5005],b[5005];
bitset <5005> G[2][5005],okl,okr,cur;
int prv[10005],ans[2][5005],p;
queue <int> Q;
void psh(int u,int v){
prv[u] = v;
if(u <= n){
assert(okl.test(u));
okl.reset(u);
}else{
assert(okr.test(u - n));
okr.reset(u - n);
if(!ans[1][u - n]) p = u - n;
}
Q.push(u);
}
void bfs(){
okl.reset();
okr.reset();
rep(u,1,n){
okl.set(u);
okr.set(u);
}
rep(u,1,n) if(!ans[0][u]) psh(u,0);
p = 0;
while(!Q.empty()) Q.pop();
while(!Q.empty()){
int u = Q.front();
Q.pop();
if(u <= n){
cur = G[0][u] & okr;
while(cur.any()){
int v = cur._Find_first();
psh(v + n,u);
cur.reset(v);
if(p) break;
}
}else{
cur = G[1][u - n] & okl;
while(cur.any()){
int v = cur._Find_first();
psh(v,u);
cur.reset(v);
if(p) break;
}
}
}
}
int _p[15],tag[25];
int brute(){
rep(i,1,n) _p[i] = i;
int result = 0,ssum;
do{
fill(tag,tag + 2 * n + 1,0);
rep(_i,1,n){
int i = _p[_i];
rep(k,a[i],b[i]) tag[k] = 0;
tag[a[i]] = tag[b[i]] = 1;
}
ssum = 0;
rep(i,1,2 * n) ssum += tag[i];
chkmax(result,ssum);
}while(next_permutation(_p + 1,_p + n + 1));
// printf("result=%d\n",result);
return result;
}
void solve(int testid){
scanf("%d",&n);
rep(i,1,n){
G[0][i].reset();
G[1][i].reset();
ans[0][i] = ans[1][i] = 0;
}
rep(i,1,n) scanf("%d%d",&a[i],&b[i]);
rep(i,1,n){
rep(j,1,n){
if(a[j] < a[i] && a[i] < b[j] && b[j] < b[i]){
G[0][i].set(j);
// printf("%d->%d\n",i,j);
}
}
}
int answer = 2 * n;
while(1){
bfs();
if(!p) break;
ans[1][p] = 1;
p += n;
int op = 1;
while(prv[p]){
if(op){
G[1][p - n].set(prv[p]);
G[0][prv[p]].reset(p - n);
}else{
G[0][p].set(prv[p] - n);
G[1][prv[p] - n].reset(p);
}
// printf("op=%d p=%d\n",op,p);
p = prv[p];
op ^= 1;
}
assert(!ans[0][p]);
ans[0][p] = 1;
answer--;
// printf("op=%d p=%d fin\n",op,p);
}
/* int answer2 = brute();
if(answer != answer2){
cerr << "output=" << answer << " answer=" << answer2 << endl;
cerr << n << endl;
rep(i,1,n) cerr << a[i] << " " << b[i] << endl;
}
assert(answer == answer2);*/
printf("%d\n",answer);
}
int main(){
// freopen("test.in","r",stdin);
// scanf("%d",&T);
T = 1;
rep(i,1,T) solve(i);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5872kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
10
result:
wrong answer 1st numbers differ - expected: '9', found: '10'