結果

問題 No.1530 Permutation and Popcount
ユーザー 👑 kmjpkmjp
提出日時 2021-06-04 23:17:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 202,576 KB
実行使用メモリ 280,176 KB
最終ジャッジ日時 2023-08-16 08:42:04
合計ジャッジ時間 8,720 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,552 KB
testcase_01 AC 5 ms
11,560 KB
testcase_02 AC 11 ms
32,112 KB
testcase_03 AC 5 ms
11,544 KB
testcase_04 AC 3 ms
7,516 KB
testcase_05 AC 5 ms
11,592 KB
testcase_06 AC 8 ms
17,892 KB
testcase_07 AC 5 ms
13,720 KB
testcase_08 AC 5 ms
11,648 KB
testcase_09 AC 5 ms
9,704 KB
testcase_10 AC 16 ms
46,512 KB
testcase_11 AC 104 ms
89,020 KB
testcase_12 AC 149 ms
122,980 KB
testcase_13 AC 25 ms
70,980 KB
testcase_14 AC 103 ms
92,496 KB
testcase_15 AC 69 ms
146,152 KB
testcase_16 AC 24 ms
73,084 KB
testcase_17 AC 119 ms
205,572 KB
testcase_18 AC 87 ms
190,384 KB
testcase_19 AC 5 ms
11,616 KB
testcase_20 AC 8 ms
23,844 KB
testcase_21 AC 110 ms
201,300 KB
testcase_22 AC 120 ms
207,300 KB
testcase_23 AC 110 ms
200,788 KB
testcase_24 AC 20 ms
62,868 KB
testcase_25 AC 99 ms
197,360 KB
testcase_26 AC 40 ms
128,360 KB
testcase_27 AC 151 ms
227,748 KB
testcase_28 AC 123 ms
208,392 KB
testcase_29 AC 49 ms
157,076 KB
testcase_30 AC 3 ms
5,460 KB
testcase_31 AC 156 ms
233,156 KB
testcase_32 AC 158 ms
232,928 KB
testcase_33 AC 157 ms
232,908 KB
testcase_34 AC 195 ms
232,868 KB
testcase_35 AC 163 ms
280,176 KB
testcase_36 AC 159 ms
280,128 KB
testcase_37 AC 158 ms
280,036 KB
testcase_38 AC 157 ms
280,036 KB
testcase_39 AC 158 ms
279,028 KB
testcase_40 AC 161 ms
278,972 KB
testcase_41 AC 155 ms
278,908 KB
testcase_42 AC 159 ms
279,504 KB
testcase_43 AC 159 ms
258,692 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