結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー snrnsidysnrnsidy
提出日時 2021-07-22 21:03:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 135,080 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2023-09-02 07:15:18
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
5,732 KB
testcase_01 AC 137 ms
5,904 KB
testcase_02 AC 135 ms
5,728 KB
testcase_03 AC 137 ms
5,772 KB
testcase_04 AC 135 ms
5,764 KB
testcase_05 AC 136 ms
5,772 KB
testcase_06 AC 136 ms
5,784 KB
testcase_07 AC 137 ms
5,744 KB
testcase_08 AC 137 ms
5,728 KB
testcase_09 AC 136 ms
5,720 KB
testcase_10 AC 136 ms
5,772 KB
testcase_11 AC 135 ms
5,724 KB
testcase_12 AC 137 ms
5,740 KB
testcase_13 AC 137 ms
5,832 KB
testcase_14 AC 136 ms
5,832 KB
testcase_15 AC 136 ms
5,732 KB
testcase_16 AC 135 ms
5,728 KB
testcase_17 AC 136 ms
5,832 KB
testcase_18 AC 136 ms
5,720 KB
testcase_19 AC 138 ms
6,044 KB
testcase_20 AC 137 ms
5,732 KB
testcase_21 AC 136 ms
5,736 KB
testcase_22 AC 136 ms
5,984 KB
testcase_23 AC 136 ms
5,724 KB
testcase_24 AC 137 ms
5,740 KB
testcase_25 AC 136 ms
5,732 KB
testcase_26 AC 136 ms
5,736 KB
testcase_27 AC 135 ms
5,740 KB
testcase_28 AC 137 ms
5,780 KB
testcase_29 AC 137 ms
5,732 KB
testcase_30 AC 134 ms
5,728 KB
testcase_31 AC 137 ms
5,720 KB
testcase_32 AC 137 ms
5,724 KB
testcase_33 AC 137 ms
5,784 KB
testcase_34 AC 137 ms
5,732 KB
testcase_35 AC 135 ms
5,768 KB
testcase_36 AC 136 ms
5,728 KB
testcase_37 AC 137 ms
5,840 KB
testcase_38 AC 136 ms
5,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>
#include <random>

using namespace std;

int dp[300001];
int history[300001];
int n;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	fill(dp, dp + 300001, 1e9);
	memset(history, -1, sizeof(history));

	dp[0] = 0;
	for (int i = 0; i <= 300000; i++)
	{
		if (dp[i] >= 1e9) continue;
		for (int j = 1; ; j+=2)
		{
			if (i + j * j > 300000) break;
			if (dp[i + j * j] >= dp[i] + j)
			{
				dp[i + j * j] = dp[i] + j;
				history[i + j * j] = i;
			}
		}
		for (int j = 2; ; j += 2)
		{
			if (i + j * j > 300000) break;
			if (dp[i + j * j] > dp[i] + j)
			{
				dp[i + j * j] = dp[i] + j;
				history[i + j * j] = i;
			}
		}
	}

	cin >> n;

	vector <int> odd, even;

	int num = n;
	while (num > 0)
	{
		int p = history[num];
		int N = sqrt(num - p);
		if (N % 2)
		{
			odd.push_back(N);
		}
		else
		{
			even.push_back(N);
		}
		num = p;
	}

	sort(odd.begin(), odd.end());
	sort(even.rbegin(), even.rend());

	for (int i = 0; i < odd.size(); i++)
	{
		int N = 0;
		for (int j = 0; j < odd[i]; j++)
		{
			cout << N;
			N = 1 - N;
		}
	}
	
	int N = 1;
	int l = 0;
	int r = even.size() - 1;
	bool ok = true;
	while (l<=r)
	{
		N = 1 - N;
		if (ok)
		{
			for (int j = 0; j < even[l]; j++)
			{
				cout << N;
				N = 1 - N;
			}
			l++;
			ok = false;
		}
		else
		{
			for (int j = 0; j < even[r]; j++)
			{
				cout << N;
				N = 1 - N;
			}
			r--;
			ok = true;
		}
	}
	cout << '\n';

	return 0;
}
0