結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー FF256grhyFF256grhy
提出日時 2020-04-16 14:01:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,122 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 184,016 KB
実行使用メモリ 22,052 KB
最終ジャッジ日時 2024-04-09 19:10:43
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int INF = 300'001;
struct B {
	pair<int, vector<int>> p;
	B(vector<int> const & v = { }) {
		p = { 0, { } };
		vector<int> even;
		RF(e, v) {
			if(e == 0) { continue; }
			p.FI += e;
			(e % 2 == 1 ? p.SE : even).PB(e);
		}
		sort(ALL(p.SE));
		sort(RALL(even));
		p.SE.PB(INF);
		deque<int> q;
		RF(e, even) { q.PB(e); }
		while(true) {
			if(q.empty()) { break; }
			int x = q.front(); q.pop_front();
			p.SE.PB(-x);
			if(q.empty()) { break; }
			int y = q.back(); q.pop_back();
			p.SE.PB(+y);
		}
	}
	friend bool operator<(B const & x, B const & y) {
		return (x.p < y.p);
	}
	friend B operator+(B const & x, B const & y) {
		vector<int> w;
		RF(e, x.p.SE) { if(e == INF) { continue; } w.PB(abs(e)); }
		RF(e, y.p.SE) { if(e == INF) { continue; } w.PB(abs(e)); }
		return w;
	}
	string str(int l, int p) const {
		string s;
		inc(i, (l + 1) / 2) { s += (p == 0 ? "01" : "10"); }
		if(l % 2 != 0) { s.pop_back(); }
		return s;
	}
	friend ostream & operator<<(ostream & os, B const & x) {
		/*
		os << x.p.FI << ": ";
		RF(e, x.p.SE) {
			os << e << " ";
		}
		os << endl;
		*/
		int p = 0;
		RF(e, x.p.SE) {
			if(e == INF) { continue; }
			os << x.str(abs(e), p);
			if(e % 2 == 0) { p ^= 1; }
		}
		return os;
	}
};

int main() {
	IN(int, n);
	B INF_B({ n + 1 });
	
	vector<B> v(n + 1, INF_B);
	incII(i, 0, n) { if(i * i > n) { continue; }
	incII(j, 0, i) { if(i * i + j * j > n) { continue; }
		setmin(v[i * i + j * j], B({ i, j }));
	}
	}
	
	B ans = INF_B;
	incII(i, 0, n) { setmin(ans, v[i] + v[n - i]); }
	OUT(ans);
}
0