結果

問題 No.2608 Divide into two
ユーザー tobbietobbie
提出日時 2024-05-06 13:48:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 659 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 167,948 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-05-06 13:49:02
合計ジャッジ時間 1,984 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int T;
  cin >> T;
  rep(i, T) {
    int N;
    cin >> N;
    int sum = 0;
    rep(i, N)
      sum += i + 1;
    if (sum % 2 != 0) {
      cout << -1 << endl;
      continue;
    }
    vector<int> v(N);
    int evn = 0, odd = 0;
    rep(i, N) {
      int j = N - i;
      if (evn + j <= sum / 2) {
	v[j - 1] = 0;
	evn += j;
      } else if (odd + j <= sum / 2) {
	v[j - 1] = 1;
	odd += j;
      }
    }
    if (evn != odd) {
      cout << -1 << endl;
      continue;
    }
    rep(i, N)
      cout << v[i];
    cout << endl;
  }
  return 0;
}
0