結果

問題 No.2247 01 ZigZag
ユーザー simansiman
提出日時 2023-03-18 16:19:13
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 1,241 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,932 KB
実行使用メモリ 18,572 KB
最終ジャッジ日時 2023-10-18 17:23:17
合計ジャッジ時間 7,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,108 KB
testcase_01 AC 83 ms
16,108 KB
testcase_02 AC 100 ms
18,108 KB
testcase_03 AC 137 ms
17,964 KB
testcase_04 AC 92 ms
16,900 KB
testcase_05 AC 86 ms
16,368 KB
testcase_06 AC 110 ms
16,824 KB
testcase_07 AC 89 ms
16,632 KB
testcase_08 AC 135 ms
18,228 KB
testcase_09 AC 140 ms
17,964 KB
testcase_10 AC 96 ms
17,424 KB
testcase_11 AC 109 ms
17,068 KB
testcase_12 AC 96 ms
16,780 KB
testcase_13 AC 101 ms
16,736 KB
testcase_14 AC 90 ms
16,896 KB
testcase_15 AC 89 ms
16,708 KB
testcase_16 AC 99 ms
16,916 KB
testcase_17 AC 160 ms
18,348 KB
testcase_18 AC 98 ms
17,688 KB
testcase_19 AC 104 ms
18,204 KB
testcase_20 AC 94 ms
17,196 KB
testcase_21 AC 97 ms
16,424 KB
testcase_22 AC 122 ms
17,572 KB
testcase_23 AC 109 ms
17,048 KB
testcase_24 AC 99 ms
18,044 KB
testcase_25 AC 130 ms
17,964 KB
testcase_26 AC 110 ms
16,928 KB
testcase_27 AC 86 ms
16,628 KB
testcase_28 AC 145 ms
18,572 KB
testcase_29 AC 153 ms
18,292 KB
testcase_30 AC 144 ms
18,228 KB
testcase_31 AC 88 ms
16,632 KB
testcase_32 AC 119 ms
17,688 KB
testcase_33 AC 105 ms
17,124 KB
testcase_34 AC 99 ms
16,792 KB
testcase_35 AC 91 ms
16,500 KB
testcase_36 AC 113 ms
17,424 KB
testcase_37 AC 94 ms
16,736 KB
testcase_38 AC 94 ms
16,656 KB
testcase_39 AC 106 ms
17,108 KB
testcase_40 AC 105 ms
18,228 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 85 ms
16,108 KB
testcase_44 AC 84 ms
16,108 KB
testcase_45 AC 161 ms
18,556 KB
testcase_46 AC 160 ms
18,556 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 82 ms
16,108 KB
testcase_50 AC 82 ms
16,108 KB
testcase_51 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:87: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N, M, K = gets.split.map(&:to_i)

def f(n, m, k)
  zero_stack = []
  one_stack = []

  (k + 1).times do |i|
    if i.even?
      zero_stack << 1
    else
      one_stack << 1
    end
  end

  if zero_stack.size > n
    return false
  end

  if one_stack.size > m
    return false
  end

  zero_stack[0] += n - zero_stack.size
  one_stack[-1] += m - one_stack.size

  res = ''
  i = 0

  while zero_stack.size > 0 || one_stack.size > 0
    if i.even?
      res << '0' * zero_stack.shift
    else
      res << '1' * one_stack.shift
    end

    i += 1
  end

  res
end

def g(n, m, k)
  zero_stack = []
  one_stack = []

  (k + 1).times do |i|
    if i.even?
      one_stack << 1
    else
      zero_stack << 1
    end
  end

  if zero_stack.size > n
    return false
  end

  if one_stack.size > m
    return false
  end

  zero_stack[0] += n - zero_stack.size
  one_stack[-1] += m - one_stack.size

  res = ''
  i = 0

  while zero_stack.size > 0 || one_stack.size > 0
    if i.even?
      res << '1' * one_stack.shift
    else
      res << '0' * zero_stack.shift
    end

    i += 1 end

  res
end

res1 = f(N, M, K)
res2 = g(N, M, K)
ans = []
ans << res1 if res1
ans << res2 if res2

if ans.empty?
  puts -1
else
  puts ans.sort.first
end
0