QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84671#5528. Least Annoying Constructive Problemjohnsonloy_xWA 2ms3472kbC++141.3kb2023-03-06 16:43:362023-03-06 16:45:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 16:45:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3472kb
  • [2023-03-06 16:43:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int mod = 1e9+7;
const int maxn = 1e6+10;

namespace IO{
	void openfile(){
		#ifndef ONLINE_JUDGE
		freopen("in.in","r",stdin);
		freopen("out.out","w",stdout);
		#endif
	}

	int add(int x,int y){
		x+=y;
		if(x>=mod)
			x-=mod;
		return x;
	}

	int sub(int x,int y){
		x-=y;
		if(x<0)
			x+=mod;
		return x;
	}

	inline int read(){
		int x = 0,f = 0;
		char c = getchar();
		while(!isdigit(c))
			f|=c=='-',c = getchar();
		while(isdigit(c))
			x = x*10+c-'0',c = getchar();
		if(f)x = -x;
		return x;
	}
}
using namespace IO;

int n; 
int vis[maxn];

int lst(int x){
	x--;
	if(!x)
		x = n;
	return x;
}

int nex(int x){
	x++;
	if(x>n)
		x = 1;
	return x;
}

void solve1(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			vis[j] = 0;
		int l = lst(i),r = nex(i);
		while(!vis[l])
			printf("%d %d\n",l,r),vis[l] = vis[r] = 1,l = lst(l),r = nex(r);
	}
}

void solve2(){
	n--;
	for(int i=1;i<=n;i++){
		int l = i,r = nex(i);
		while(l!=r)
			printf("%d %d\n",l,r),l = lst(l),r = nex(r);
		printf("%d %d\n",l,n+1);
	}
}

signed main(){
//	openfile();
	n = read();
	if(n&1)
		solve1();
	else solve2();
	return 0;
}
//»¹Í¦nbµÄ¹¹ÔìÌâ
//¾ÍÊÇ°ÑÍêȫͼµÄÆ¥ÅäÄóöÀ´µ¥×ö 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3

output:

3 2
1 3
2 1

result:

wrong answer Integer 2 violates the range [4, 3]