結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー tac
提出日時 2019-09-01 17:25:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,149 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 175,892 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 06:38:06
合計ジャッジ時間 4,374 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 11 WA * 25
権限があれば一括ダウンロードができます

ソースコード

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;
    
    
    priority_queue<int> q;
    priority_queue<int, vector<int>, greater<int> > q2;
    
    {
        int now = n;
        q.push(sqrt(from[now]));
        q2.push(sqrt(from[now]));
        
        while (1) {
            now -= from[now];
            if (from[now] == -1) break;
            q.push(sqrt(from[now]));
            q2.push(sqrt(from[now]));
        }
    }
    
    /*
    while (!q.empty()) {
        cout << q.top() << endl;
        q.pop();
    }
    */
    
    n = sz(q);
    string str;
    rep(i, n) {
        int now = (sz(str) ? str.back() - '0' : 0);
        // cout << now << endl;
        if (now == 0) {
            // cout << q.top() << endl;
            rep(j, q.top()) {
                str += now + '0';
                now ^= 1;
            }
            q.pop();
        } else {
            // cout << q2.top() << endl;
            rep(j, q2.top()) {
                str += now + '0';
                now ^= 1;
            }
            q2.pop();
        }
        
    }
    
    cout << str << endl;
}
0