Submission #16840108
Source Code Expand
import Foundation
// 第一引数に二分探索したい配列を渡す
// 第二引数に検索したい要素を渡す
// 第三引数に二分探索したい配列の大きさを渡す
func binarySearch(list:[Int],item:Int,cnt:Int)->Int{
// 解の存在範囲を初期化
var low = -1
var high = cnt
// 解の存在範囲が1より大きい間、繰り返す
while (high - low > 1) {
let mid = Int(floor(Double(low + high) / 2))
if list[mid] >= item {
// midが条件を満たせば、解の存在範囲は(low,mid]
high = mid
} else {
// midが条件を満たさなければ、解の存在範囲は(mid,high]
low = mid
}
}
// この時点で、low + 1 = highとなっている
return high
}
// 標準入力の受け取り
let n = Int(readLine()!)!
var a = readLine()!.split(separator:" ").map{Int($0)!}
var b = readLine()!.split(separator:" ").map{Int($0)!}
var c = readLine()!.split(separator:" ").map{Int($0)!}
// とりあえず各配列をソートする
a.sort { $0 < $1 }
b.sort { $0 < $1 }
c.sort { $0 < $1 }
// 答えを入れる変数を用意
var ans = 0;
// 中部のパーツの配列に対して全探索
for i in b{
// 各配列に対して二分探索
let ai = binarySearch(list:a,item:i,cnt:n)
let ci = binarySearch(list:c,item:i+1,cnt:n)
// ansに考えられるパーツの組み合わせの個数を加える
ans += (ai)*(n-ci)
}
// 答えを出力
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | C - Snuke Festival |
| User | tardigrade |
| Language | Swift (5.2.1) |
| Score | 300 |
| Code Size | 1574 Byte |
| Status | AC |
| Exec Time | 619 ms |
| Memory | 23104 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 619 ms | 22624 KiB |
| 02.txt | AC | 572 ms | 22308 KiB |
| 03.txt | AC | 435 ms | 22564 KiB |
| 04.txt | AC | 434 ms | 22392 KiB |
| 05.txt | AC | 279 ms | 22700 KiB |
| 06.txt | AC | 277 ms | 22844 KiB |
| 07.txt | AC | 223 ms | 23056 KiB |
| 08.txt | AC | 222 ms | 22776 KiB |
| 09.txt | AC | 185 ms | 22872 KiB |
| 10.txt | AC | 187 ms | 22492 KiB |
| 11.txt | AC | 175 ms | 22620 KiB |
| 12.txt | AC | 179 ms | 22548 KiB |
| 13.txt | AC | 561 ms | 22520 KiB |
| 14.txt | AC | 565 ms | 22632 KiB |
| 15.txt | AC | 564 ms | 22732 KiB |
| 16.txt | AC | 553 ms | 22636 KiB |
| 17.txt | AC | 562 ms | 22588 KiB |
| 18.txt | AC | 563 ms | 22416 KiB |
| 19.txt | AC | 569 ms | 22404 KiB |
| 20.txt | AC | 163 ms | 22784 KiB |
| 21.txt | AC | 169 ms | 22420 KiB |
| 22.txt | AC | 619 ms | 23104 KiB |
| 23.txt | AC | 570 ms | 22740 KiB |
| 24.txt | AC | 563 ms | 22832 KiB |
| 25.txt | AC | 572 ms | 22412 KiB |
| 26.txt | AC | 13 ms | 13224 KiB |
| 27.txt | AC | 8 ms | 13708 KiB |
| 28.txt | AC | 11 ms | 13216 KiB |
| 29.txt | AC | 9 ms | 13396 KiB |
| s1.txt | AC | 14 ms | 13612 KiB |
| s2.txt | AC | 20 ms | 13796 KiB |
| s3.txt | AC | 11 ms | 13392 KiB |