結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー heno239heno239
提出日時 2019-08-30 21:57:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,478 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 110,672 KB
実行使用メモリ 18,948 KB
最終ジャッジ日時 2023-09-06 06:49:52
合計ジャッジ時間 4,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 12 ms
5,432 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 28 ms
7,196 KB
testcase_35 WA -
testcase_36 AC 120 ms
13,360 KB
testcase_37 WA -
testcase_38 AC 248 ms
18,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

bool chked[300001];
int leng[300001];
int lengdfs(int n) {
	if (n == 0)return 0;
	if (chked[n])return leng[n];
	chked[n] = true;
	int ret = mod;
	rep1(j, n) {
		if (j*j > n)break;
		ret = min(ret, j + lengdfs(n - j * j));
	}
	return leng[n] = ret;
}



void solve() {
	int n; cin >> n;
	int cur = lengdfs(n);
	string ans;
	int id = 0;
	while (n > 0) {
		bool ansed = false;
		for (int i = 1; i <= n; i+=2) {
			if (n - i * i < 0)break;
			int sum = i + leng[n - i * i];
			//cout << cur << " " << sum << endl;
			if (sum == cur) {
				rep(j, i) {
					if (j % 2 == 0)ans.push_back('0');
					else ans.push_back('1');
				}
				n -= i * i; cur -= i;
				ansed = true;
				break;
			}
		}
		if (!ansed)break;
	}
	while (n > 0) {
		if (id == 0) {
			for (int i = 2; i <= n; i += 2) {
				if (n - i * i < 0)break;
				int sum = i + leng[n - i * i];
				if (sum == cur) {
					rep(j, i) {
						if (j % 2 == 0)ans.push_back('0');
						else ans.push_back('1');
					}
					n -= i * i; cur -= i;
					break;
				}
			}
		}
		else {
			int k = sqrt(n + 1); k = (k / 2) * 2 + 2;
			for (int i = k; i >=2 ; i -= 2) {
				if (n - i * i < 0)continue;
				int sum = i + leng[n - i * i];
				if (sum == cur) {
					rep(j, i) {
						if (j % 2 == 0)ans.push_back('1');
						else ans.push_back('0');
					}
					n -= i * i; cur -= i;
					break;
				}
			}
		}
		id ^= 1;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}
0