結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー Shuz*Shuz*
提出日時 2019-08-15 00:14:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,167 ms / 2,000 ms
コード長 5,842 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 176,940 KB
実行使用メモリ 247,532 KB
最終ジャッジ日時 2023-09-02 07:06:50
合計ジャッジ時間 11,073 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 428 ms
113,812 KB
testcase_01 AC 224 ms
61,328 KB
testcase_02 AC 1,030 ms
236,364 KB
testcase_03 AC 775 ms
194,700 KB
testcase_04 AC 3 ms
5,644 KB
testcase_05 AC 3 ms
5,460 KB
testcase_06 AC 3 ms
5,448 KB
testcase_07 AC 3 ms
5,456 KB
testcase_08 AC 194 ms
54,844 KB
testcase_09 AC 3 ms
5,564 KB
testcase_10 AC 3 ms
5,508 KB
testcase_11 AC 3 ms
5,568 KB
testcase_12 AC 61 ms
18,416 KB
testcase_13 AC 3 ms
5,500 KB
testcase_14 AC 3 ms
5,448 KB
testcase_15 AC 3 ms
5,452 KB
testcase_16 AC 4 ms
5,440 KB
testcase_17 AC 3 ms
5,572 KB
testcase_18 AC 3 ms
5,576 KB
testcase_19 AC 3 ms
5,444 KB
testcase_20 AC 3 ms
5,456 KB
testcase_21 AC 3 ms
5,444 KB
testcase_22 AC 3 ms
5,444 KB
testcase_23 AC 3 ms
5,496 KB
testcase_24 AC 3 ms
5,488 KB
testcase_25 AC 3 ms
5,564 KB
testcase_26 AC 4 ms
5,444 KB
testcase_27 AC 3 ms
5,452 KB
testcase_28 AC 3 ms
5,492 KB
testcase_29 AC 3 ms
5,732 KB
testcase_30 AC 3 ms
5,508 KB
testcase_31 AC 4 ms
5,556 KB
testcase_32 AC 32 ms
12,032 KB
testcase_33 AC 9 ms
6,312 KB
testcase_34 AC 127 ms
36,068 KB
testcase_35 AC 1,135 ms
247,488 KB
testcase_36 AC 520 ms
131,480 KB
testcase_37 AC 1,167 ms
247,532 KB
testcase_38 AC 1,131 ms
247,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
const ll LINF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [" << endl;                      \
        rep(__i, h) {                                                          \
            rep(__j, w) { cerr << a[__i][__j] << space; }                      \
            cerr << endl;                                                      \
        }                                                                      \
        cerr << "]" << endl;                                                   \
    }

#define vdump(a, n)                                                            \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [";                              \
        rep(__i, n) if (__i) cerr << space << a[__i];                          \
        else cerr << a[__i];                                                   \
        cerr << "]" << endl;                                                   \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
run(0) { fasten, fout(10); }

// Speed
#pragma GCC optimize("O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

inline constexpr ll modulo(const ll n, const ll m = MOD) {
    if (n < 0) {
        return n % m + m;
    } else if (n >= m) {
        return n % m;
    } else {
        return n;
    }
}

inline constexpr ll chmod(ll &n, const ll m = MOD) { return n = modulo(n, m); }

inline constexpr ll mpow(ll a, ll n, const ll m = MOD) {
    ll r = 1;
    while (n) {
        if (n & 1) r *= a;
        chmod(r, m);
        a *= a;
        chmod(a, m);
        n >>= 1;
    }
    return r;
}

struct Factor {
    inline vector<ll> factors(ll N) {
        vector<ll> A;
        ll i = 2;
        while (i * i <= N) {
            if (N % i == 0) {
                A.push_back(i);
                N /= i;
            } else {
                i++;
            }
        }
        if (N != 1) A.push_back(N);
        sort(all(A));
        return A;
    }
    inline vector<ll> divisor(ll N) {
        vector<ll> A = factors(N), B;
        ll a = A.size();
        rep(i, 1 << a) {
            ll d = 1;
            rep(j, a) if (i & (1 << j)) d *= A[j];
            B.push_back(d);
        }
        sort(all(B)), B.erase(unique(all(B)), B.end());
        return B;
    }
};

struct csum {
    ll N;
    vector<ll> A, S;
    csum(vector<ll> v) : A(v), S(1) { each(k, v) S.push_back(k + S.back()); }
    ll sum(ll l, ll r) { return S[r] - S[l]; }
    ll lsum(ll r) { return S[r]; }
    ll rsum(ll l) { return S.back() - S[l]; }
};

signed main() {
    ll N;
    cin >> N;
    vector<pair<ll, string>> DP(N + 1, {INF, ""});
    DP[0] = {0, ""};
    string S[1000], T[1000];
    S[1] = "0", T[1] = "1";
    inc(i, 2, 999) S[i] = S[i - 1] + (i & 1 ? '0' : '1'),
                   T[i] = T[i - 1] + (i & 1 ? '1' : '0');
    rep(i, N + 1) {
        inc(j, 1, sqrt(i)) {
            ll id = i - j * j;
            if (DP[id].fi + j < DP[i].fi) {
                string t;
                if (id == 0 || DP[id].se.back() == '0') {
                    t = S[j];
                } else {
                    t = T[j];
                }
                DP[i] = {DP[id].fi + j, DP[id].se + t};
            }
            if (DP[id].fi + j == DP[i].fi) {
                string t;
                if (id == 0 || DP[id].se.back() == '0') {
                    t = S[j];
                } else {
                    t = T[j];
                }
                chmin(DP[i].se, DP[id].se + t);
            }
        }
    }
    cout << DP[N].se << endl;
}
0