QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243428#1807. Distribute the BarslaosongWA 1ms4756kbC++141.6kb2023-11-08 10:50:442023-11-08 10:50:44

Judging History

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

  • [2023-11-08 10:50:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4756kb
  • [2023-11-08 10:50:44]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mm(a,b) memset(a,b,sizeof(a))
//priority_queue<int,vector<int>,greater<int>>q;//升序队列 
//priority_queue<int,vector<int>,less<int>>q;//降序队列 
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=300010;
const int mod=1e9+7;

int v[100010],vv[100010]={0},cnt=0;
stack<int>st;
vector<int>vec[50010];

int check(int x){
	int num=(x*x)/(2*x-1);
	for(int i=num;i>=2;i--){
		if((x*x)%i==0)return i;
	} 
	return 0;
}

void solve1(int n){
	cout<<n/2<<endl;
	for(int i=1,j=n;i<=n/2;i++,j--){
		cout<<"2 "<<i<<" "<<j<<endl;
	}
	return ;
}

int dfs(int x,int fa){
	if(x==0){
		while(!st.empty()){
			vec[cnt].push_back(st.top());
			vv[st.top()]=1;
			st.pop();
		}
		return 1;
	}
	for(int i=fa-2;i>=0;i-=2){
		if(!vv[i]&&x-i>=0){
			st.push(i);
			if(dfs(x-i,i))return 1;
			st.pop();
		}
	}
	return 0;
}


void solve2(int n){
	int q=check(n);
	if(!q){
		cout<<"-1";
		return ;
	}
	q=(n*n)/q;
	for(int i=2*n-1;i>=1;i-=2){
		if(!vv[i]){
			vv[i]=1;cnt++;
			st.push(i);
			dfs(q-i,i);
		}
	}
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++){
		cout<<vec[i].size()<<" ";
		for(int j=0;j<vec[i].size();j++)cout<<vec[i][j]<<" ";
		cout<<endl;
	}
}

void solve(){
	int n;
	cin>>n;
	if(n==2||n==1)cout<<"-1";
	else if(n%2==0)solve1(n);
	else solve2(n);
//	for(int i=5;i<=101;i+=2){
//		if(check(i))cout<<i<<endl;
//	} 
}

int main(){
	IOS;
	int _=1;
//	cin>>_;while(_--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4756kb

input:

4

output:

2
2 1 4
2 2 3

result:

wrong answer Even numbers not allowed