結果
| 問題 |
No.2608 Divide into two
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-20 20:40:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 1,000 ms |
| コード長 | 837 bytes |
| コンパイル時間 | 1,577 ms |
| コンパイル使用メモリ | 169,232 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-28 05:45:47 |
| 合計ジャッジ時間 | 2,048 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 |
ソースコード
#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';
}
}