結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー heno239heno239
提出日時 2019-08-30 21:47:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,544 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 113,156 KB
実行使用メモリ 87,480 KB
最終ジャッジ日時 2023-09-06 06:46:28
合計ジャッジ時間 7,453 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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 memo[300001][2];
string res[300001][2];

string thmin(string &a, string &b) {
	if (a.size() < b.size())return a;
	else if (a.size() > b.size())return b;
	else {
		return min(a, b);
	}
}

string dfs(int n,int cur) {
	if (n == 0) {
		return "";
	}
	if (memo[n][cur])return res[n][cur];
	memo[n][cur] = true;
	int len = 1;
	string ret;
	string al;
	int nw = cur;
	while (len*len <= n) {
		al.push_back('0' + nw); nw ^= 1;
		int tid = cur;
		if (len % 2 == 0)tid ^= 1;
		int to = n - len * len;
		string nex = al + dfs(to, tid);
		if (ret == "")ret = nex;
		else {
			ret = thmin(ret, nex);
		}
		len++;
	}
	return res[n][cur] = ret;
}

void solve() {
	int n; cin >> n;
	cout << dfs(n, 0) << endl; return;
	string ans;
	int cur = 0;
	vector<int> od,ev;
	while (n > 0) {
		int k = sqrt(n + 0.1); cout << k << endl;
		if (k % 2)od.push_back(k);
		else ev.push_back(k);
		//v.push_back(k);
		n -= k * k;
		/*rep(i, k) {
			ans.push_back('0'+cur);
			cur ^= 1;
		}
		cur ^= 1; n -= k * k;*/
	}
	sort(od.begin(), od.end());
	rep(i, od.size()) {
		rep(j, od[i]) {
			if (j % 2 == 0)ans.push_back('0');
			else ans.push_back('1');
		}
	}
	sort(ev.begin(), ev.end());
	int l = 0, r = (int)ev.size() - 1;
	while (l <= r) {
		rep(j, ev[r]) {
			if (j % 2 == 0)ans.push_back('0');
			else ans.push_back('1');
		}
		r--;
		if (l > r)break;
		rep(j, ev[l]) {
			if (j % 2 == 0)ans.push_back('1');
			else ans.push_back('0');
		}
		l++;
	}
	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