結果

問題 No.308 素数は通れません
ユーザー rickythetarickytheta
提出日時 2015-12-01 22:09:41
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,061 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 15,680 KB
最終ジャッジ日時 2023-10-12 07:26:36
合計ジャッジ時間 18,069 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
15,384 KB
testcase_01 AC 101 ms
15,284 KB
testcase_02 AC 107 ms
15,428 KB
testcase_03 AC 106 ms
15,428 KB
testcase_04 AC 110 ms
15,524 KB
testcase_05 AC 115 ms
15,464 KB
testcase_06 AC 117 ms
15,616 KB
testcase_07 AC 105 ms
15,424 KB
testcase_08 AC 104 ms
15,368 KB
testcase_09 AC 107 ms
15,336 KB
testcase_10 AC 131 ms
15,428 KB
testcase_11 AC 130 ms
15,380 KB
testcase_12 AC 106 ms
15,492 KB
testcase_13 AC 136 ms
15,492 KB
testcase_14 AC 134 ms
15,288 KB
testcase_15 AC 110 ms
15,424 KB
testcase_16 AC 111 ms
15,324 KB
testcase_17 AC 107 ms
15,396 KB
testcase_18 AC 107 ms
15,540 KB
testcase_19 AC 107 ms
15,348 KB
testcase_20 AC 108 ms
15,292 KB
testcase_21 AC 108 ms
15,432 KB
testcase_22 AC 107 ms
15,584 KB
testcase_23 AC 108 ms
15,332 KB
testcase_24 AC 109 ms
15,376 KB
testcase_25 AC 110 ms
15,460 KB
testcase_26 AC 108 ms
15,492 KB
testcase_27 AC 109 ms
15,580 KB
testcase_28 AC 109 ms
15,360 KB
testcase_29 AC 107 ms
15,348 KB
testcase_30 AC 106 ms
15,292 KB
testcase_31 AC 108 ms
15,400 KB
testcase_32 AC 126 ms
15,584 KB
testcase_33 AC 107 ms
15,568 KB
testcase_34 AC 108 ms
15,324 KB
testcase_35 AC 106 ms
15,420 KB
testcase_36 AC 98 ms
15,328 KB
testcase_37 AC 95 ms
15,516 KB
testcase_38 AC 95 ms
15,456 KB
testcase_39 AC 96 ms
15,512 KB
testcase_40 AC 94 ms
15,432 KB
testcase_41 AC 96 ms
15,324 KB
testcase_42 AC 95 ms
15,620 KB
testcase_43 AC 97 ms
15,456 KB
testcase_44 AC 96 ms
15,572 KB
testcase_45 AC 96 ms
15,400 KB
testcase_46 AC 96 ms
15,320 KB
testcase_47 AC 95 ms
15,348 KB
testcase_48 AC 96 ms
15,376 KB
testcase_49 AC 95 ms
15,548 KB
testcase_50 AC 93 ms
15,452 KB
testcase_51 AC 95 ms
15,420 KB
testcase_52 AC 95 ms
15,344 KB
testcase_53 AC 99 ms
15,340 KB
testcase_54 AC 97 ms
15,524 KB
testcase_55 AC 97 ms
15,424 KB
testcase_56 AC 97 ms
15,536 KB
testcase_57 AC 96 ms
15,284 KB
testcase_58 AC 97 ms
15,380 KB
testcase_59 AC 97 ms
15,352 KB
testcase_60 AC 95 ms
15,332 KB
testcase_61 AC 95 ms
15,288 KB
testcase_62 AC 94 ms
15,464 KB
testcase_63 AC 95 ms
15,564 KB
testcase_64 AC 96 ms
15,420 KB
testcase_65 AC 96 ms
15,312 KB
testcase_66 AC 94 ms
15,364 KB
testcase_67 AC 95 ms
15,424 KB
testcase_68 AC 93 ms
15,284 KB
testcase_69 AC 94 ms
15,432 KB
testcase_70 AC 94 ms
15,488 KB
testcase_71 AC 94 ms
15,464 KB
testcase_72 AC 95 ms
15,320 KB
testcase_73 AC 94 ms
15,568 KB
testcase_74 AC 95 ms
15,320 KB
testcase_75 AC 96 ms
15,540 KB
testcase_76 AC 96 ms
15,424 KB
testcase_77 AC 95 ms
15,288 KB
testcase_78 AC 94 ms
15,588 KB
testcase_79 AC 95 ms
15,328 KB
testcase_80 AC 98 ms
15,632 KB
testcase_81 AC 103 ms
15,416 KB
testcase_82 AC 96 ms
15,388 KB
testcase_83 AC 95 ms
15,344 KB
testcase_84 AC 346 ms
15,496 KB
testcase_85 AC 95 ms
15,384 KB
testcase_86 TLE -
testcase_87 TLE -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

N_MAX = 110
$mp = Array.new(N_MAX).map{Array.new(N_MAX,0)}
$used = Array.new(N_MAX).map{Array.new(N_MAX,false)}
$n = gets.chomp.to_i

$vx = [1,0,-1,0]
$vy = [0,1,0,-1]
def dfs(w,h,y,x)
  return false if y<0 || x<0 || y>=h || x>=w
  return false if $used[y][x]
  $used[y][x] = true
  return false if $mp[y][x]==1e9
  return true if $mp[y][x]==$n
  t = $mp[y][x]
  return false if Prime.prime?(t)
  for i in 0...4
    return true if dfs(w,h,y+$vy[i],x+$vx[i])
  end
  return false
end

if $n<100
  for w in 3...$n
    h = $n/w + ( $n%w == 0 ? 0 : 1 )
    for i in 0...N_MAX
      for j in 0...N_MAX
        $mp[i][j] = 1e9
        if i<h && j<w && i*w+j<$n
          $mp[i][j] = i*w+j+1
        end
        $used[i][j] = false
      end
    end
    if dfs(w,h,0,0)
      puts w
      break
    end
  end
else
  c = 8
  while true
    # process
    if $n%c!=1
      puts c
      break
    end
    if !Prime.prime?($n-c)
      puts c
      break
    end
    # succeed
    while true
      c += 2
      break if !Prime.prime?(c+1)
    end
  end
end
0