QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725646#5423. Perfect Matchingbugmaker3243WA 2ms7716kbC++233.0kb2024-11-08 19:11:332024-11-08 19:11:33

Judging History

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

  • [2024-11-08 19:11:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7716kb
  • [2024-11-08 19:11:33]
  • 提交

answer

#include<bits/stdc++.h>
#define N 500005
//#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
#define gc() getchar()
#define fi first
#define se second
#define Kamisato return
#define Ayaka 0;
#define file(_s) freopen(#_s".in","r",stdin);freopen(#_s".out","w",stdout);
//#define CHECK_MEMORY ___JQH___
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9;
const ll INF=2e18;
bool Memory_Begin;
namespace IO{const int SIZE=(1<<21)+1;char ibuf[SIZE],*iS,*iT,obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1,c,qu[55];int f,qr;inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf,fflush(stdout);}inline void putc(char x){*oS++=x;if(oS==oT)flush();}template <class I>inline void read(I &x){for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;}template <class I>inline void print(I x){if(!x)putc('0');if(x<0)putc('-'),x=-x;while(x)qu[++qr]=x%10+'0',x/=10;while(qr)putc(qu[qr --]);}inline void reads(string &s){s.clear();for(c=gc();c<33||c>126;)c=gc();for(;c>=33&&c<=126;c=gc())s.push_back(c);}inline void prints(string s){for(char c:s)putc(c);}struct Flusher_ {~Flusher_(){flush();}}io_flusher_;}
using IO::read;using IO::putc;using IO::print;using IO::reads;using IO::prints;
template<class I>I updiv(I x,I y){return (x%y==0?x/y:x/y+1);}
template<class I>bool cmin(I &x,I y){if(x>y)return x=y,1;return 0;}
template<class I>bool cmax(I &x,I y){if(x<y)return x=y,1;return 0;}

int n,a[N],L,R;
map<int,int>mpL,mpR;
vector<pii>s[N];
bool vst[N];
int calc(int x)
{
	queue<int>q;
	q.push(x),vst[x]=1;
	int res=0;
	while(q.size())
	{
		int x=q.front();
		res+=s[x].size();
		q.pop();
		for(pii i:s[x])
		{
			int y=i.fi;
			if(!vst[y]) q.push(y),vst[y]=1;
		}
	}
	return res/2;
}
vector<pii>ans;
bool usefa[N];
void dfs(int x,int prt,int pre)
{
	vector<int>las;
	for(pii i:s[x])
	{
		int y=i.fi,id=i.se;
		if(y==prt) continue;
		dfs(y,x,id);
		if(!usefa[y]) las.push_back(id);
	}
	if(las.size()&1) assert(pre),las.push_back(pre),usefa[x]=1;
	for(int i=0;i<(int)las.size();i+=2) ans.push_back({las[i],las[i+1]});
}
void solve()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i]),mpL[i-a[i]]=mpR[i+a[i]]=0;
	for(auto &p:mpL) p.se=++L;
	for(auto &p:mpR) p.se=L+(++R);
	for(int i=1;i<=n;i++)
	{
		int x=mpL[i-a[i]],y=mpR[i+a[i]];
		s[x].push_back({y,i});
		s[y].push_back({x,i});
	}
	for(int i=1;i<=L+R;i++)
		if(!vst[i])
		{
			if(calc(i)&1) return prints("No\n");
			continue;
			dfs(i,0,0);
		}
	prints("Yes\n");
	for(pii p:ans) print(p.fi),putc(' '),print(p.se),putc('\n');
}
void clear()
{
	ans.clear(),mpL.clear(),mpR.clear();
	for(int i=1;i<=L+R;i++) s[i].clear(),vst[i]=usefa[i]=0;
	L=R=0;
}
bool Memory_End;
signed main()
{
#ifdef CHECK_MEMORY
	cerr<<"Memory: "<<(&Memory_End-&Memory_Begin)/1048576.0<<" MiB\n";
#endif
	int T; read(T);
	while(T--) solve(),clear();
	Kamisato Ayaka
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7716kb

input:

3
6
14 22 33 11 25 36
4
100 10 98 12
4
1 3 5 7

output:

Yes
Yes
No

result:

wrong output format Expected integer, but "Yes" found (test case 1)