QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317839#6414. Classical Maximization ProblemEndlineWA 0ms3756kbC++142.4kb2024-01-29 20:15:302024-01-29 20:15:31

Judging History

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

  • [2024-01-29 20:15:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-01-29 20:15:30]
  • 提交

answer

/*
 * Author: Endline
 * Time: 2024/01/29 19:51:47
 * File: Graph-B.cpp
 */
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
using ll=long long;
const int MAXN=400002;
const int mod=998244353;
template<typename _Tp>inline void Add(_Tp&x,ll y){x=x+y>=mod?x+y-mod:x+y;}
template<typename _Tp>inline void Mul(_Tp&x,ll y){x=x*y>=mod?x*y%mod:x*y;}
int T,n,len,ecnt,acnt;
bool used[MAXN];
int pos[MAXN],head[MAXN],vis[MAXN];
pair<int,int>a[MAXN],ans[MAXN];
struct edge
{
    int v,id,nxt;
}e[MAXN<<1];
inline void addedge(int u,int v,int id)
{
    e[++ecnt]={v,id,head[u]};
    head[u]=ecnt;
}
void dfs(int u,int pre)
{
    vis[u]=1;
    vector<int>bck,son;
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(e[i].id==pre)continue;
        if(vis[v]==1)bck.push_back(e[i].id);
        else if(vis[v]!=2)
        {
            dfs(v,e[i].id);
            if(!used[e[i].id])son.push_back(e[i].id);
        }
    }
    while(son.size()>=2)
    {
        ans[++acnt]={son[son.size()-1],son[son.size()-2]};
        son.pop_back(),son.pop_back();
    }
    while(bck.size()>=2)
    {
        ans[++acnt]={bck[bck.size()-1],bck[bck.size()-2]};
        bck.pop_back(),bck.pop_back();
    }
    if(son.size()&&bck.size())
    {
        ans[++acnt]={son.back(),bck.back()};
        son.pop_back(),bck.pop_back();
    }
    if(son.size()&&pre)ans[++acnt]={pre,son.back()},used[pre]=true;
    if(bck.size()&&pre)ans[++acnt]={pre,bck.back()},used[pre]=true;
    vis[u]=2;
}
inline void solve()
{
    cin>>n;acnt=ecnt=0;
    for(int i=1;i<=n*2;i++)
    {
        cin>>a[i].first>>a[i].second;
        tie(pos[i*2-1],pos[i*2])=a[i];
    }
    sort(pos+1,pos+n*4+1);
    len=unique(pos+1,pos+n*4+1)-pos-1;
    for(int i=1;i<=len;i++)head[i]=0;
    for(int i=1;i<=n*2;i++)
    {
        int p1=lower_bound(pos+1,pos+len+1,a[i].first)-pos,p2=lower_bound(pos+1,pos+len+1,a[i].second)-pos;
        addedge(p1,p2,i);
        if(p1!=p2)addedge(p2,p1,i);
    }
    for(int i=1;i<=len;i++)vis[i]=0,used[i]=false;
    for(int i=1;i<=len;i++)
        if(!vis[i])dfs(i,0);
    printf("%d\n",acnt);
    for(int i=1;i<=acnt;i++)
        printf("%d %d\n",ans[i].first,ans[i].second);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>T;
    while(T--)solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3756kb

input:

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

output:

2
2 4
3 1
2
2 3
4 1
0

result:

wrong output format Unexpected end of file - int32 expected (test case 3)