結果

問題 No.1530 Permutation and Popcount
ユーザー kotatsugamekotatsugame
提出日時 2021-06-04 22:08:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 73,892 KB
実行使用メモリ 6,908 KB
最終ジャッジ日時 2023-08-16 08:40:59
合計ジャッジ時間 3,330 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
6,536 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 5 ms
5,992 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 5 ms
6,092 KB
testcase_23 AC 4 ms
5,912 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 3 ms
4,448 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 6 ms
6,684 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 5 ms
6,636 KB
testcase_36 AC 6 ms
6,676 KB
testcase_37 AC 6 ms
6,632 KB
testcase_38 AC 6 ms
6,744 KB
testcase_39 AC 6 ms
6,752 KB
testcase_40 AC 6 ms
6,908 KB
testcase_41 AC 6 ms
6,744 KB
testcase_42 AC 6 ms
6,704 KB
testcase_43 AC 5 ms
6,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:14:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   14 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<bitset>
#include<vector>
using namespace std;
int N,M;
int cnt[301];
bitset<90001>dp[301];
int f(vector<int>A)
{
	int ret=0;
	for(int a:A)for(int b:A)ret+=!__builtin_parity(a*b);
	return ret;
}
main()
{
	cin>>N>>M;
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=N;j++)
		{
			int t=!__builtin_parity(i*j);
			cnt[i]+=t;
		}
		M-=cnt[i];
		//cnt[i]+=!__builtin_parity(i*i);
		cnt[i]*=2;
	}
	M=-M;
	if(M<0)
	{
		cout<<-1<<endl;
		return 0;
	}
	dp[0][0]=1;
	for(int i=1;i<=N;i++)
	{
		dp[i]=dp[i-1]|dp[i-1]<<cnt[i];
	}
	if(dp[N][M]==0)cout<<-1<<endl;
	else
	{
		vector<int>X,Y;
		for(int i=N;i>0;i--)
		{
			if(M>=cnt[i]&&dp[i-1][M-cnt[i]])
			{
				Y.push_back(i);
				M-=cnt[i];
			}
			else X.push_back(i);
		}
		cout<<X.size()<<" "<<Y.size()<<endl;
		for(int i=0;i<X.size();i++)cout<<X[i]<<(i+1==X.size()?"\n":" ");
		for(int i=0;i<Y.size();i++)cout<<Y[i]<<(i+1==Y.size()?"\n":" ");
		cerr<<f(X)<<" "<<f(Y)<<endl;
	}
}
0