結果

問題 No.2608 Divide into two
ユーザー Today03Today03
提出日時 2024-01-19 21:37:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 722 bytes
コンパイル時間 1,917 ms
コンパイル使用メモリ 202,800 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-01-19 21:37:18
合計ジャッジ時間 2,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int N;
		cin >> N;
		int M = N * (N + 1) / 2;
		if (M % 2 == 1) {
			cout << -1 << endl;
		} else {
			M /= 2;
			int now = 0, sum = 0;
			vector<char> ans(N, '0');
			while (sum + now + 1 <= M) {
				now++;
				sum += now;
				ans[now - 1] = '1';
			}
			if (sum < M) {
				int d = M - sum;
				if (N - d <= now) {
					ans[N - d - 1] = '0';
					ans[N - 1] = '1';
				} else {
					ans[now - 1] = '0';
					ans[now + d - 1] = '1';
				}
			}
			for (int i = 0; i < N; i++) cout << ans[i];
			cout << endl;
		}
	}
}
0