結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー | semisagi |
提出日時 | 2020-07-17 22:18:50 |
言語 | Swift (5.10.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 1,496 bytes |
コンパイル時間 | 1,363 ms |
コンパイル使用メモリ | 130,976 KB |
実行使用メモリ | 20,392 KB |
最終ジャッジ日時 | 2024-05-07 22:34:01 |
合計ジャッジ時間 | 5,862 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
11,988 KB |
testcase_01 | AC | 10 ms
11,136 KB |
testcase_02 | AC | 10 ms
11,136 KB |
testcase_03 | AC | 131 ms
19,260 KB |
testcase_04 | AC | 151 ms
20,236 KB |
testcase_05 | AC | 131 ms
19,388 KB |
testcase_06 | AC | 121 ms
18,756 KB |
testcase_07 | AC | 150 ms
20,224 KB |
testcase_08 | AC | 17 ms
11,580 KB |
testcase_09 | AC | 88 ms
16,256 KB |
testcase_10 | AC | 145 ms
20,384 KB |
testcase_11 | AC | 9 ms
11,136 KB |
testcase_12 | AC | 153 ms
20,392 KB |
testcase_13 | AC | 150 ms
20,176 KB |
testcase_14 | AC | 152 ms
20,288 KB |
testcase_15 | AC | 10 ms
11,136 KB |
testcase_16 | AC | 9 ms
11,264 KB |
testcase_17 | AC | 10 ms
11,136 KB |
testcase_18 | AC | 10 ms
11,008 KB |
testcase_19 | AC | 9 ms
11,136 KB |
testcase_20 | AC | 10 ms
11,136 KB |
testcase_21 | AC | 10 ms
11,264 KB |
testcase_22 | AC | 10 ms
11,264 KB |
testcase_23 | AC | 20 ms
11,960 KB |
testcase_24 | AC | 58 ms
14,508 KB |
testcase_25 | AC | 115 ms
18,312 KB |
testcase_26 | AC | 34 ms
13,408 KB |
testcase_27 | AC | 71 ms
15,024 KB |
testcase_28 | AC | 94 ms
16,168 KB |
testcase_29 | AC | 122 ms
18,640 KB |
testcase_30 | AC | 146 ms
19,788 KB |
testcase_31 | AC | 43 ms
13,824 KB |
testcase_32 | AC | 31 ms
12,840 KB |
testcase_33 | AC | 131 ms
19,276 KB |
testcase_34 | AC | 10 ms
11,136 KB |
testcase_35 | AC | 9 ms
11,136 KB |
testcase_36 | AC | 10 ms
11,136 KB |
testcase_37 | AC | 10 ms
11,136 KB |
testcase_38 | AC | 10 ms
11,264 KB |
testcase_39 | AC | 10 ms
11,136 KB |
ソースコード
struct Scanner { private var stack = [String]() private var index = 0 mutating func peek() -> String { if stack.count == index { stack += readLine()!.split(separator: " ").map{ String($0) } } return stack[index] } mutating func next() -> String { let value = peek() index += 1 return value } mutating func nextInt() -> Int { return Int(next())! } mutating func nextDouble() -> Double { return Double(next())! } } var scanner = Scanner() let N = scanner.nextInt() let A = (0 ..< N).map { _ in scanner.nextInt() - 1 } let B = (0 ..< N).map { _ in scanner.nextInt() - 1 } var I = [Int](repeating: 0, count: N) for i in A.indices { I[A[i]] = i } struct Counter { static let size = 500 var this = [Int](repeating: 0, count: size * size) var these = [Int](repeating: 0, count: size) mutating func increment(_ index: Int) { this[index] += 1 these[index / Self.size] += 1 } func count(le: Int) -> Int { var value = 0 var k = le while k % Self.size != 0 { value += this[k] k += 1 } k /= Self.size while k < Self.size { value += these[k] k += 1 } return value } } var counter = Counter() var answer = 0 for x in B { answer += counter.count(le: I[x]) counter.increment(I[x]) } print(answer)