結果

問題 No.2608 Divide into two
ユーザー maeshunmaeshun
提出日時 2024-01-20 10:58:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 1,000 ms
コード長 1,582 bytes
コンパイル時間 4,389 ms
コンパイル使用メモリ 266,192 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-20 10:58:38
合計ジャッジ時間 5,161 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int m = n*(n+1)/2;
        if(m%2){
            cout << -1 << endl;
            continue;
        }
        vector<vector<bool>> dp(n+1, vector<bool>(m));
        dp[0][0] = 1;
        rep(i,n){
            rep(j,m+1){
                if(!dp[i][j]) continue;
                if(j+i+1<=m) dp[i+1][j+i+1] = dp[i][j];
                dp[i+1][j] = dp[i][j];
            }
        }
        if(!dp[n][m/2]){
            cout << -1 << endl;
            continue;
        }
        int now = m/2;
        vector<int> ans;
        for(int i=n-1;i>=0;i--){
            if(now-i-1<0) {
                ans.push_back(0);
            }
            else{
                if(dp[i][now-i-1]) {
                    now -= (i+1);
                    ans.push_back(1);
                }
                else{
                    ans.push_back(0);
                }
            }
        }
        reverse(ans.begin(),ans.end());
        for(int a : ans){
            cout << a;
        }
        cout << endl;
    }
    return 0;
}
0