結果

問題 No.2608 Divide into two
ユーザー t98slidert98slider
提出日時 2024-01-20 20:40:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 1,000 ms
コード長 837 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 169,188 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-20 20:40:15
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 6 ms
6,676 KB
testcase_02 AC 36 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        if(n * (n + 1) % 4 != 0){
            cout << -1 <<'\n';
            continue;
        }
        int r = n * (n + 1) / 4;
        vector<int> dp(r + 1, -2);
        dp[0] = -1;
        for(int i = 1; i <= n; i++){
            for(int j = r - i; j >= 0; j--){
                if(dp[j] == -2) continue;
                if(dp[i + j] == -2) dp[i + j] = i;
            }
        }
        if(dp[r] == -2){
            cout << -1 << '\n';
            continue;
        }
        string ans(n, '0');
        while(dp[r] != -1){
            ans[dp[r] - 1] = '1';
            r -= dp[r];
        }
        cout << ans << '\n';
    }
}
0