提出 #67007860
ソースコード 拡げる
read_line.to_i.times do
puts solve()
end
def solve
n, m = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i64).sort.reverse
b = read_line.split.map(&.to_i64).sort
b += b.map { |v| v + m }
left = b.bsearch_index { |v, _| v + a[0] >= m }.not_nil! % n
if ok(a, b, m, 0, left)
return 0
end
lo = 0
hi = m - 1
while hi - lo > 1
if hi > lo * 2
mid = ((hi.to_i64 * {1, lo}.max) ** 0.5).round.to_i
else
mid = (hi + lo) // 2
end
if ok(a, b, m, mid, left)
hi = mid
else
lo = mid
end
end
hi
end
def ok(a, b, m, ans, left)
n = a.size
return false if (a[0] + b[left]) % m > ans
right = left
while right < left + n
break if (a[0] + b[right + 1]) % m > ans
right += 1
end
need = left
1.upto(n - 1) do |i|
need += 1
prev_left = left
prev_right = right
while true
break if a[i] + b[left] >= m
left += 1
end
return false if (a[i] + b[left]) % m > ans
while right < left + n
break if (a[i] + b[(right + 1) % n]) % m > ans
right += 1
end
if prev_right + 1 < left
return false
end
if right < need
return false
end
need = {need, left}.max
end
return right >= left + n - 1
end
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Match, Mod, Minimize |
| ユーザ | tomerun |
| 言語 | Crystal (Crystal 1.9.1) |
| 得点 | 0 |
| コード長 | 1318 Byte |
| 結果 | WA |
| 実行時間 | 455 ms |
| メモリ | 32164 KiB |
コンパイルエラー
I: Dependencies are satisfied I: Building: main
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 700 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample-01.txt |
| All | 01-01.txt, 01-02.txt, 01-03.txt, 01-05.txt, 01-06.txt, 01-07.txt, 02-01.txt, 02-02.txt, 02-03.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 04-01.txt, 04-02.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, sample-01.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01-01.txt | WA | 347 ms | 4460 KiB |
| 01-02.txt | WA | 319 ms | 4396 KiB |
| 01-03.txt | WA | 275 ms | 4580 KiB |
| 01-05.txt | WA | 265 ms | 4544 KiB |
| 01-06.txt | WA | 331 ms | 4668 KiB |
| 01-07.txt | WA | 384 ms | 8852 KiB |
| 02-01.txt | WA | 410 ms | 31640 KiB |
| 02-02.txt | WA | 430 ms | 31744 KiB |
| 02-03.txt | WA | 453 ms | 31832 KiB |
| 03-01.txt | WA | 430 ms | 31724 KiB |
| 03-02.txt | WA | 395 ms | 31756 KiB |
| 03-03.txt | WA | 429 ms | 31756 KiB |
| 03-04.txt | WA | 447 ms | 31732 KiB |
| 03-05.txt | WA | 455 ms | 31756 KiB |
| 04-01.txt | AC | 101 ms | 31748 KiB |
| 04-02.txt | AC | 43 ms | 24356 KiB |
| 05-01.txt | AC | 86 ms | 31672 KiB |
| 05-02.txt | WA | 125 ms | 31648 KiB |
| 05-03.txt | AC | 107 ms | 31816 KiB |
| 05-04.txt | WA | 138 ms | 32164 KiB |
| 05-05.txt | WA | 236 ms | 31732 KiB |
| 05-06.txt | WA | 216 ms | 31652 KiB |
| sample-01.txt | WA | 1 ms | 3720 KiB |