結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー leaf_1415leaf_1415
提出日時 2019-09-01 01:35:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 72,616 KB
実行使用メモリ 5,980 KB
最終ジャッジ日時 2023-09-06 11:58:30
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
4,720 KB
testcase_01 WA -
testcase_02 AC 184 ms
5,680 KB
testcase_03 AC 147 ms
5,504 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 34 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 193 ms
5,816 KB
testcase_36 AC 92 ms
5,024 KB
testcase_37 AC 191 ms
5,980 KB
testcase_38 AC 190 ms
5,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <algorithm>
#include <queue>
#include <vector>
#define llint long long

using namespace std;

llint n;
llint dp[300005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 0; i <= n; i++) dp[i] = 1e9;
	dp[0] = 0;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j*j <= i; j++){
			dp[i] = min(dp[i], dp[i-j*j]+j);
		}
	}
	//for(int i = 0; i <= n; i++) cout << i << " " << dp[i] << endl;
	
	vector<llint> vec;
	llint rem = n, cnt = dp[n];
	for(llint i = 1; i <= rem; i+=2){
		llint mx = 0;
		for(llint j = 1; i*i*j <= rem; j++){
			if(dp[rem-i*i*j] == cnt-i*j) mx = j;
		}
		for(llint j = 0; j < mx; j++) vec.push_back(i);
		rem -= mx*i*i, cnt -= mx*i;
	}
	for(llint i = (n+1)/2*2; i >= 2; i-=2){
		llint mx = 0;
		for(llint j = 1; i*i*j <= rem; j++){
			if(dp[rem-i*i*j] == cnt-i*j) mx = j;
		}
		for(llint j = 0; j < mx; j++) vec.push_back(i);
		rem -= mx*i*i, cnt -= mx*i;
	}
	
	vector<llint> ovec, evec;
	for(int i = 0; i < vec.size(); i++){
		if(vec[i]%2) ovec.push_back(vec[i]);
		else evec.push_back(vec[i]);
	}
	sort(evec.rbegin(), evec.rend());
	
	vec.clear();
	for(int i = 0; i < ovec.size(); i++) vec.push_back(ovec[i]);
	llint m = evec.size();
	for(int i = 0; i < m; i++){
		if(i%2) vec.push_back(evec[m-1-i/2]);
		else vec.push_back(evec[i]);
	}
	
	string ans;
	for(int i = 0; i < vec.size(); i++){
		for(int j = 0; j < vec[i]; j++) ans += ('0' + (i%2));
	}
	for(int i = 0; i < ans.size(); i++){
		if(i%2){
			if(ans[i] == '0') ans[i] = '1';
			else ans[i] = '0';
		}
	}
	cout << ans << endl;
	
	return 0;
}
0