結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー QCFiumQCFium
提出日時 2019-08-30 22:05:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 175,468 KB
実行使用メモリ 5,824 KB
最終ジャッジ日時 2023-09-06 06:53:44
合計ジャッジ時間 4,689 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 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 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 18 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 78 ms
4,956 KB
testcase_37 WA -
testcase_38 AC 158 ms
5,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	assert(scanf("%d", &n) == 1);
	return n;
}
int main () {
	int n = ri();
	std::pair<int, int> dp[n + 1];// {val, cost}
	for (int i = 0; i <= n; i++) dp[i] = {1000000000, -1};
	dp[n] = {0, 0};
	for (int i = n; i >= 0; i--) {
		for (int j = 0; j * j <= i; j++) {
			if (dp[i - j * j].first > dp[i].first + j) {
				dp[i - j * j].first = dp[i].first + j;
				dp[i - j * j].second = j;
			}
		}
	}
	std::vector<int> rens;
	int cur = 0;
	while (cur < n) {
		rens.push_back(dp[cur].second);
		cur += dp[cur].second * dp[cur].second;
	}
	std::sort(rens.begin(), rens.end());
	assert(cur == n);
	/*
	for (auto i : rens) std::cerr << i << " ";
	std::cerr << std::endl;*/
	std::deque<int> odds, evens;
	for (auto i : rens) (i % 2 ? odds : evens).push_back(i);
	std::string res;
	for (auto i : odds) {
		if (!res.size()) res.push_back('0');
		else res.push_back(res.back());
		for (int j = 0; j + 1 < i ; j++) res.push_back(!(res.back() - '0') + '0');
	}
	int cnt = 0;
	while (evens.size()) {
		int v;
		if (cnt++ % 2) {
			v = evens.back();
			evens.pop_back();
		} else {
			v = evens.front();
			evens.pop_front();
		}
		if (!res.size()) res.push_back('0');
		else res.push_back(res.back());
		for (int j = 0; j + 1 < v; j++) res.push_back(!(res.back() - '0') + '0');
	}
	std::cout << res << std::endl;
	return 0;
}
0