結果

問題 No.1530 Permutation and Popcount
ユーザー 👑 kmjpkmjp
提出日時 2021-06-04 23:17:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 204,696 KB
実行使用メモリ 64,256 KB
最終ジャッジ日時 2024-05-03 17:35:53
合計ジャッジ時間 6,800 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 9 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 12 ms
5,376 KB
testcase_11 AC 81 ms
22,272 KB
testcase_12 AC 120 ms
56,832 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 83 ms
25,984 KB
testcase_15 AC 43 ms
7,424 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 99 ms
35,072 KB
testcase_18 AC 73 ms
17,920 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 98 ms
30,464 KB
testcase_22 AC 105 ms
36,864 KB
testcase_23 AC 88 ms
29,696 KB
testcase_24 AC 14 ms
5,376 KB
testcase_25 AC 81 ms
23,808 KB
testcase_26 AC 30 ms
5,376 KB
testcase_27 AC 121 ms
58,496 KB
testcase_28 AC 100 ms
38,016 KB
testcase_29 AC 36 ms
6,016 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 129 ms
64,128 KB
testcase_32 AC 128 ms
64,128 KB
testcase_33 AC 131 ms
64,256 KB
testcase_34 AC 128 ms
64,128 KB
testcase_35 AC 129 ms
64,128 KB
testcase_36 AC 130 ms
64,128 KB
testcase_37 AC 129 ms
64,256 KB
testcase_38 AC 134 ms
64,128 KB
testcase_39 AC 127 ms
63,104 KB
testcase_40 AC 129 ms
63,104 KB
testcase_41 AC 133 ms
62,976 KB
testcase_42 AC 135 ms
63,616 KB
testcase_43 AC 104 ms
40,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int P[303];

int from[303][400000];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	from[0][100000]=1;
	for(i=1;i<=N;i++) {
		for(j=1;j<=N;j++) {
			if(__builtin_popcount(i*j)%2==0) P[i]++;
		}
		FOR(j,200000) if(from[i-1][j]) {
			from[i][j+P[i]]=1;
			from[i][j-P[i]]=-1;
		}
	}
	
	if(from[N][100000+M]==0) {
		cout<<-1<<endl;
	}
	else {
		vector<int> A,B;
		while(N>0) {
			if(from[N][100000+M]==1) {
				A.push_back(N);
				M-=P[N];
			}
			else {
				B.push_back(N);
				M+=P[N];
			}
			N--;
		}
		reverse(ALL(A));
		reverse(ALL(B));
		cout<<A.size()<<" "<<B.size()<<endl;
		FOR(i,A.size()) {
			cout<<A[i];
			if(i==A.size()-1) {
				cout<<endl;
			}
			else {
				cout<<" ";
			}
		}
		FOR(i,B.size()) {
			cout<<B[i];
			if(i==B.size()-1) {
				cout<<endl;
			}
			else {
				cout<<" ";
			}
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0