結果

問題 No.2608 Divide into two
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2024-01-19 23:31:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,119 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 250,836 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-01-19 23:31:39
合計ジャッジ時間 3,330 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

    int N = 100;

    vector<vector<int>> dp(N+1,vector<int>(N*N,-1));

    dp[0][0] = 0;

    for (int i = 1; i <= N; i++){

        for (int j = 0; j <= N*N; j++){
            if (dp[i-1][j] == -1) continue;
            dp[i][j] = dp[i-1][j];
            if (j+i > N*N) continue;
            dp[i][j+i] = j;

        }
    }
	
    int t;
    cin >> t;

    for (int i = 0; i < t; i++){

        int n;
        cin >> n;

        int sum = n*(n+1)/2;

        if (sum & 1 ) {
            cout << -1 << endl;
            continue;
        }
        int half = sum / 2;

        if (dp[n][half] == -1){
            cout << -1 << endl;
            continue;
        }

        vector<int> ans(n);

        int now = half;

        for (int j = n;j > 0;j--){
            int nex = dp[j][now];

            if (nex == now) continue;

            ans[now-nex-1] = 1;

            now = nex; 
        }

        for (auto a : ans){
            cout << a;
        }
        cout << endl;
    }
    
    return 0;

}
0