結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー QCFiumQCFium
提出日時 2019-08-30 22:17:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,923 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 175,076 KB
実行使用メモリ 7,164 KB
最終ジャッジ日時 2023-09-06 06:58:24
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 61 ms
4,872 KB
testcase_02 AC 251 ms
6,948 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 51 ms
4,708 KB
testcase_09 AC 2 ms
4,504 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 14 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,388 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 8 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 32 ms
4,380 KB
testcase_35 AC 265 ms
6,972 KB
testcase_36 AC 138 ms
5,856 KB
testcase_37 AC 267 ms
7,164 KB
testcase_38 AC 262 ms
6,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	assert(scanf("%d", &n) == 1);
	return n;
}
int main () {
	int n = ri();
	struct Info {
		int cost;
		int one_cost;
		int odds_min;
		Info (int cost, int one_cost, int odds_min) : cost(cost), one_cost(one_cost), odds_min(odds_min) {}
		Info () : cost(1000000000), one_cost(-1), odds_min(1000000000){}
	};
	Info dp[n + 1];// {val, cost}
	for (int i = 0; i <= n; i++) dp[i] = {1000000000, -1, -1};
	dp[n] = {0, 0, 0};
	for (int i = n; i >= 0; i--) {
		for (int j = 0; j * j <= i; j++) {
			if (dp[i - j * j].cost > dp[i].cost + j) {
				dp[i - j * j].cost = dp[i].cost + j;
				dp[i - j * j].one_cost = j;
				dp[i - j * j].odds_min = std::min(dp[i].odds_min, j % 2 ? j : 1000000000);
			} else if (dp[i - j * j].cost == dp[i].cost + j) {
				if (dp[i - j * j].odds_min > std::min(dp[i].odds_min, j % 2 ? j : 1000000000)) {
					dp[i - j * j].odds_min = std::min(dp[i].odds_min, j % 2 ? j : 1000000000);
					dp[i - j * j].one_cost = j;
				}
			}
		}
	}
	std::vector<int> rens;
	int cur = 0;
	while (cur < n) {
		rens.push_back(dp[cur].one_cost);
		cur += dp[cur].one_cost * dp[cur].one_cost;
	}
	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 == 0) {
			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