Submission #5330013


Source Code Expand

Copy
parseInt(x) = parse(Int, x)

function main()
  N = readline() |> parseInt
  # A = readdlm(STDIN, Int)
  A = map(parseInt, split(readline()))

  a_gcd = Array{Int}(N)
  a_gcd[1] = A[1]
  for i in 2:N
    a_gcd[i] = gcd(a_gcd[i - 1], A[i])
  end

  a_gcd_r = Array{Int}(N)
  a_gcd_r[end] = A[end]
  for i in N-1:-1:1
    a_gcd_r[i] = gcd(a_gcd_r[i + 1], A[i])
  end

  a = map(1:N) do i
    if i == 1
      a_gcd_r[2]
    elseif i == N
      a_gcd[end - 1]
    else
      gcd(a_gcd[i - 1], a_gcd_r[i + 1])
    end
  end
  # println(a)
  result = maximum(a)

  println(result)
end

main()

Submission Info

Submission Time
Task C - GCD on Blackboard
User yuntan_t
Language Julia (0.5.0)
Score 300
Code Size 619 Byte
Status
Exec Time 505 ms
Memory 141580 KB

Test Cases

Set Name Score / Max Score Test Cases
All 300 / 300 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 467 ms 117768 KB
sample_02 412 ms 112284 KB
sample_03 412 ms 110592 KB
testcase_01 469 ms 128000 KB
testcase_02 505 ms 139272 KB
testcase_03 412 ms 111436 KB
testcase_04 498 ms 141580 KB
testcase_05 463 ms 126820 KB
testcase_06 496 ms 136456 KB
testcase_07 411 ms 111072 KB
testcase_08 415 ms 111320 KB
testcase_09 483 ms 128772 KB
testcase_10 486 ms 128544 KB
testcase_11 486 ms 128500 KB
testcase_12 415 ms 112048 KB
testcase_13 412 ms 110468 KB