結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー nebukuro09nebukuro09
提出日時 2019-08-30 22:30:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 204,552 KB
実行使用メモリ 16,652 KB
最終ジャッジ日時 2023-09-06 06:59:34
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:15:29: 警告: overflow in conversion from ‘long long int’ to ‘int’ changes value from ‘576460752303423488’ to ‘0’ [-Woverflow]
   15 |     REP(i, N+1) dp[i] = 1LL << 59;
      |                         ~~~~^~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

int N;
int dp[303030];
vector<bool> ans[303030];
vector<bool> tmp;

void solve() {
    cin >> N;
    REP(i, N+1) dp[i] = 1LL << 59;

    dp[0] = 0;

    REP(i, N) for (ll j = 1; i + j * j <= N; ++j) {
        if (dp[i] + j < dp[i + j * j]) {
            dp[i + j * j] = dp[i] + j;
            ans[i + j * j] = ans[i];
            int last = i == 0 ? 0 : ans[i].back();
            REP(_, j) ans[i + j * j].push_back(last), last ^= 1;
        } else if (dp[i] + j == dp[i + j * j]) {
            tmp = ans[i];
            int last = i == 0 ? 0 : ans[i].back();
            REP(_, j) tmp.push_back(last), last ^= 1;
            ans[i + j * j] = min(ans[i + j * j], tmp);
        }
    }

    REP(i, ans[N].size()) cout << ans[N][i] ? 1 : 0;
    cout << "\n";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0