結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー pirozhkipirozhki
提出日時 2019-10-14 11:35:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 94,716 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-09-02 07:12:31
合計ジャッジ時間 5,684 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
5,228 KB
testcase_01 AC 107 ms
4,496 KB
testcase_02 AC 441 ms
6,408 KB
testcase_03 AC 361 ms
6,276 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 95 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 28 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,388 KB
testcase_21 AC 1 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,384 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 15 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 60 ms
4,380 KB
testcase_35 AC 465 ms
6,676 KB
testcase_36 AC 242 ms
5,544 KB
testcase_37 AC 472 ms
6,484 KB
testcase_38 AC 467 ms
6,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <limits.h>

using namespace std;

struct node{
	int next_min;
	int next_max;
	int cost;
};

int main() {
	int n; cin >> n;
	vector<node> table(n + 1);
	for (int i = 1; i <= n; i++) {
		int rt = static_cast<int>(sqrt(i));
		vector<int> v(rt + 1, INT_MAX), w;
		for (int j = 1; j <= rt; j++) {
			v[j] = j + table[i - j * j].cost;
		}
		int cost_min = *min_element(v.begin(), v.end());
		for (unsigned int i = 0; i < v.size(); i++) {
			if (v[i] == cost_min) {
				w.push_back(i);
			}
		}
		if (w.size() > 1) {
			auto pos = partition(w.begin(), w.end(), [](int& x) { return x % 2; });
			sort(w.begin(), pos);
			sort(pos, w.end(), greater<int>());
		}
		table[i] = { w.front(), w.back(), cost_min };
	}

	bool b = 0;
	while (n) {
		int next;
		if (b) {
			next = table[n].next_max;
		}
		else {
			next = table[n].next_min;
		}
		for (int j = 0; j < next; j++) {
			cout << b;
			b ^= 1;
		}
		b ^= 1;
		n -= next * next;
	}
	return 0;
}
0