結果

問題 No.873 バイナリ、ヤバいなり!w
コンテスト
ユーザー vjudge1
提出日時 2026-09-18 19:48:11
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 827 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 934 ms
コンパイル使用メモリ 181,108 KB
実行使用メモリ 10,024 KB
最終ジャッジ日時 2026-09-18 19:48:15
合計ジャッジ時間 3,796 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int dp[300005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    
    for (int i = 1; i * i <= N; i++) {
        int w = i * i;
        for (int j = w; j <= N; j++) {
            dp[j] = min(dp[j], dp[j - w] + i);
        }
    }
    
    int n = N;
    int s = 0;
    string ans = "";
    
    while (n > 0) {
        for (int l = 1; l * l <= n; l++) {
            if (dp[n - l * l] == dp[n] - l) {
                for (int i = 0; i < l; i++) {
                    ans += (s + i) % 2 + '0';
                }
                s = (s + l - 1) % 2;
                n -= l * l;
                break;
            }
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}
0