結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー tactac
提出日時 2019-09-01 17:50:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,104 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 173,404 KB
実行使用メモリ 5,976 KB
最終ジャッジ日時 2023-09-06 12:00:51
合計ジャッジ時間 4,335 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 37 ms
5,804 KB
testcase_02 AC 152 ms
5,696 KB
testcase_03 AC 124 ms
5,692 KB
testcase_04 AC 3 ms
5,752 KB
testcase_05 AC 3 ms
5,852 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 3 ms
5,936 KB
testcase_08 AC 33 ms
5,764 KB
testcase_09 AC 3 ms
5,708 KB
testcase_10 AC 4 ms
5,752 KB
testcase_11 AC 3 ms
5,732 KB
testcase_12 AC 10 ms
5,780 KB
testcase_13 AC 4 ms
5,704 KB
testcase_14 AC 2 ms
5,696 KB
testcase_15 AC 3 ms
5,756 KB
testcase_16 AC 3 ms
5,960 KB
testcase_17 AC 3 ms
5,740 KB
testcase_18 AC 2 ms
5,736 KB
testcase_19 AC 4 ms
5,700 KB
testcase_20 AC 3 ms
5,676 KB
testcase_21 AC 3 ms
5,760 KB
testcase_22 AC 4 ms
5,720 KB
testcase_23 AC 4 ms
5,684 KB
testcase_24 AC 3 ms
5,708 KB
testcase_25 AC 3 ms
5,828 KB
testcase_26 AC 3 ms
5,856 KB
testcase_27 AC 3 ms
5,724 KB
testcase_28 AC 4 ms
5,708 KB
testcase_29 AC 3 ms
5,948 KB
testcase_30 AC 2 ms
5,684 KB
testcase_31 AC 3 ms
5,680 KB
testcase_32 AC 6 ms
5,724 KB
testcase_33 AC 3 ms
5,740 KB
testcase_34 AC 22 ms
5,784 KB
testcase_35 AC 160 ms
5,736 KB
testcase_36 AC 83 ms
5,860 KB
testcase_37 AC 161 ms
5,696 KB
testcase_38 AC 159 ms
5,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
    int n;
    cin >> n;
    
    const int MAX_N = 300001;
    int dp[MAX_N];
    rep(i, MAX_N) dp[i] = inf;
    dp[0] = 0;
    dp[1] = 1;
    
    int from[MAX_N];
    fill_n(from, MAX_N, -1);
    from[1] = 1;
    
    rep3(i, 2, n + 1) for (int j = 1; j * j <= i; ++j) {
        if (dp[i] > dp[i - j * j] + j) {
            dp[i] = dp[i - j * j] + j;
            from[i] = j * j;
        }
    }
    // rep(i, n + 1) cout << dp[i] << " "; cout << endl;
    // rep(i, n + 1) cout << from[i] << " "; cout << endl;
    
    
    vector<int> o, e;
    
    {
        int now = n;
        int tmp = sqrt(from[now]);
        if (tmp % 2) o.eb(tmp);
        else e.eb(tmp);
        
        while (1) {
            now -= from[now];
            if (from[now] == -1) break;
            tmp = sqrt(from[now]);
            if (tmp % 2) o.eb(tmp);
            else e.eb(tmp);
        }
    }
    
    sort(e.rbegin(), e.rend());
    vector<int> e2;
    int turn = (sz(e) + 1) / 2;
    rep(i, turn) {
        e2.eb(e[i]);
        int b = sz(e) - 1 - i;
        if (i != b) e2.eb(e[b]);
    }
    // rep(i, sz(e2)) cout << e2[i] << " "; cout << endl;
    
    n = sz(o) + sz(e);
    string str;
    rep(i, sz(o)) {
        int now = 0;
        rep(j, o[i]) {
            str += now + '0';
            now ^= 1;
        }
    }
    
    rep(i, sz(e2)) {
        int now = (sz(str) ? str.back() - '0' : 0);
        rep(j, e2[i]) {
            str += now + '0';
            now ^= 1;
        }
    }
    
    cout << str << endl;
}
0