結果

問題 No.1530 Permutation and Popcount
ユーザー inksamuraiinksamurai
提出日時 2021-06-05 05:29:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,155 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 105,344 KB
実行使用メモリ 231,904 KB
最終ジャッジ日時 2023-08-16 08:42:40
合計ジャッジ時間 6,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,544 KB
testcase_01 AC 4 ms
7,484 KB
testcase_02 AC 8 ms
17,720 KB
testcase_03 AC 4 ms
7,500 KB
testcase_04 AC 3 ms
5,468 KB
testcase_05 AC 4 ms
7,724 KB
testcase_06 AC 5 ms
9,600 KB
testcase_07 AC 4 ms
7,572 KB
testcase_08 AC 4 ms
7,460 KB
testcase_09 AC 4 ms
5,452 KB
testcase_10 AC 11 ms
23,940 KB
testcase_11 AC 71 ms
159,064 KB
testcase_12 AC 105 ms
226,608 KB
testcase_13 AC 18 ms
40,288 KB
testcase_14 AC 74 ms
169,312 KB
testcase_15 AC 41 ms
93,796 KB
testcase_16 AC 17 ms
38,320 KB
testcase_17 AC 85 ms
189,744 KB
testcase_18 AC 65 ms
146,812 KB
testcase_19 AC 4 ms
7,520 KB
testcase_20 AC 7 ms
13,684 KB
testcase_21 AC 79 ms
179,600 KB
testcase_22 AC 87 ms
193,868 KB
testcase_23 AC 80 ms
179,572 KB
testcase_24 AC 14 ms
32,076 KB
testcase_25 AC 72 ms
163,244 KB
testcase_26 AC 28 ms
64,884 KB
testcase_27 AC 105 ms
227,700 KB
testcase_28 AC 87 ms
195,920 KB
testcase_29 AC 34 ms
79,452 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 109 ms
231,792 KB
testcase_32 AC 110 ms
231,796 KB
testcase_33 AC 108 ms
231,604 KB
testcase_34 AC 109 ms
231,732 KB
testcase_35 AC 109 ms
231,600 KB
testcase_36 AC 110 ms
231,652 KB
testcase_37 AC 108 ms
231,644 KB
testcase_38 AC 108 ms
231,904 KB
testcase_39 AC 108 ms
230,792 KB
testcase_40 AC 107 ms
230,832 KB
testcase_41 AC 107 ms
231,096 KB
testcase_42 AC 108 ms
231,236 KB
testcase_43 AC 91 ms
200,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <list>
#include <tuple>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <functional>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(s) vector<s>
#define rsz(a,n) a.resize(n)
#define rszv(a,n,v) a.resize(n,v)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
 
const int max_n = 200000;
 
using namespace std;

// int f(vi a) {
// 	int cnt=0;
// 	rep(i,sz(a)) {
// 		rep(j,sz(a)) {
// 			int c=__builtin_popcount(a[i]*a[j]);
// 			if(c%2==0) cnt++;
// 		}
// 	}
// 	return cnt;
// }

int n,m;
int dp[301][max_n];
int val[301];

int main(){
fcin;
	cin>>n>>m;
	
	const int zro=max_n/2;

	dp[0][zro]=1;
	
	crep(a,1,n+1) {
		crep(b,1,n+1){
			int c=__builtin_popcount(a*b);
			if(c%2==0) val[a]++;
		}

		rep(j,max_n) {
			if(dp[a-1][j]) { dp[a][j+val[a]]=1; dp[a][j-val[a]]=1; }
		}
	}

	if(!dp[n][m+zro]) {cout<<"-1\n"; exit(0);}
 	
 	vi ansx , ansy;

 	int nwval = m+zro;
 
 	while(n>0) {
		if(nwval-val[n]>=0 and dp[n-1][nwval-val[n]] == 1) {ansx.pb(n); nwval -= val[n];}
		else if(nwval+val[n]<max_n and dp[n-1][nwval+val[n]] == 1) {ansy.pb(n); nwval += val[n];}
 		n--;
 	}
 	// cout << f(ansx) << "\n";
 	cout << sz(ansx) << " " << sz(ansy) << "\n";
 	for(auto x : ansx)cout<<x<<" ";
 	cout<<"\n";
 	for(auto x : ansy)cout<<x<<" ";

/*
*/
 
    return 0;   
}
0