QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#243432#1807. Distribute the BarslaosongWA 1ms4600kbC++141.7kb2023-11-08 11:06:182023-11-08 11:06:18

Judging History

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

  • [2023-11-08 11:06:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4600kb
  • [2023-11-08 11:06:18]
  • 提交

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,op=1;
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){
//		cout<<cnt<<"$$"<<st.size()<<endl; 
		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;
	cout<<q<<endl;
	for(int i=2*n-1;i>=1;i-=2){
		if(!vv[i]){
			vv[i]=1;cnt++;
			st.push(i);
//			cout<<i<<"##"<<cnt<<endl;
			dfs(q-i,i);
			if(vec[cnt].size()==0){
				op=-1;
				break;
			}
		}
	}
	if(op==-1){
		cout<<"-1";
		return ;
	}
	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);
}

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

详细

Test #1:

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

input:

4

output:

2
2 1 4
2 2 3

result:

wrong answer Even numbers not allowed