結果

問題 No.2247 01 ZigZag
コンテスト
ユーザー chro_96
提出日時 2023-03-26 01:52:28
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,316 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 415 ms
コンパイル使用メモリ 41,740 KB
最終ジャッジ日時 2026-02-22 10:20:23
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int k = 0;
  
  int res = 0;
  
  char ans[200001] = "";
  
  int a = 1;
  int b = 0;
  int c = 0;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  res = scanf("%d", &k);
  
  if ((n == m && (k >= 2*n)) || (n < m && k > 2*n) || (n > m && k > 2*m) || (k == 0 && n > 0 && m > 0)) {
    printf("-1\n");
    return 0;
  }
  
  if (n < m && k >= 2*n) {
    int idx = 0;
    while (n > 0) {
      ans[idx] = '1';
      ans[idx+1] = '0';
      n--;
      m--;
      idx += 2;
    }
    while (m > 0) {
      ans[idx] = '1';
      m--;
      idx++;
    }
    ans[idx] = '\0';
  } else if (k >= 2*m) {
    int idx = 0;
    while (n > m) {
      ans[idx] = '0';
      n--;
      idx++;
    }
    while (m > 0) {
      ans[idx] = '1';
      ans[idx+1] = '0';
      n--;
      m--;
      idx += 2;
    }
    ans[idx] = '\0';
  } else {
    int idx = 0;
    while (2*n > k) {
      ans[idx] = '0';
      n--;
      idx++;
    }
    while (k > 2) {
      ans[idx] = '1';
      ans[idx+1] = '0';
      n--;
      m--;
      k -= 2;
      idx += 2;
    }
    while (m > 0) {
      ans[idx] = '1';
      m--;
      idx++;
    }
    while (n > 0) {
      ans[idx] = '0';
      n--;
      idx++;
    }
    ans[idx] = '\0';
  }
  
  printf("%s\n", ans);
  return 0;
}
0