提出 #17978677
ソースコード 拡げる
func readInt4(line: Int = #line, file: String = #file) -> (Int, Int, Int, Int) {
guard let string = readLine() else {
preconditionFailure("No input (at line \(line) in \(file))")
}
let values: [Int] = string.split(separator: " ").map { part in
guard let value = Int(part) else {
preconditionFailure("Illegal input value: \(string) (at line \(line) in \(file))")
}
return value
}
precondition(values.count == 4, "Illegal number of input values: count = \(values.count), values = \(values) (at line \(line) in \(file))")
return (values[0], values[1], values[2], values[3])
}
func readInt2(line: Int = #line, file: String = #file) -> (Int, Int) {
guard let string = readLine() else {
preconditionFailure("No input (at line \(line) in \(file))")
}
let values: [Int] = string.split(separator: " ").map { part in
guard let value = Int(part) else {
preconditionFailure("Illegal input value: \(string) (at line \(line) in \(file))")
}
return value
}
precondition(values.count == 2, "Illegal number of input values: count = \(values.count), values = \(values) (at line \(line) in \(file))")
return (values[0], values[1])
}
struct Array2D<Element>: Sequence {
let width: Int
let height: Int
private(set) var elements: [Element]
init(width: Int, height: Int, elements: [Element]) {
precondition(elements.count == width * height)
self.width = width
self.height = height
self.elements = elements
}
init(width: Int, height: Int, element: Element) {
self.init(width: width, height: height, elements: [Element](repeating: element, count: width * height))
}
var count: Int { width * height }
var xRange: Range<Int> { 0 ..< width }
var yRange: Range<Int> { 0 ..< height }
private func indexAt(x: Int, y: Int) -> Int {
precondition(xRange.contains(x))
precondition(yRange.contains(y))
return y * width + x
}
subscript(x: Int, y: Int) -> Element {
get { elements[indexAt(x: x, y: y)] }
set { elements[indexAt(x: x, y: y)] = newValue }
}
func makeIterator() -> IndexingIterator<[Element]> {
elements.makeIterator()
}
func map<T>(_ transform: (Element) throws -> T) rethrows -> Array2D<T> {
try Array2D<T>(width: width, height: height, elements: elements.map(transform))
}
}
let (h, w, n, m) = readInt4()
enum Cell {
case light
case block
case none
}
var map: Array2D<Cell> = .init(width: w, height: h, element: .none)
var lightMap: Array2D<Bool> = .init(width: w, height: h, element: false)
for _ in 0 ..< n {
let (b, a) = readInt2()
map[a - 1, b - 1] = .light
}
for _ in 0 ..< m {
let (d, c) = readInt2()
map[c - 1, d - 1] = .block
}
for y in map.yRange {
var isLighting = false
for x in map.xRange {
switch map[x, y] {
case .light:
isLighting = true
case .block:
isLighting = false
case .none:
break
}
if isLighting {
lightMap[x, y] = true
}
}
}
for y in map.yRange {
var isLighting = false
for x in map.xRange.reversed() {
switch map[x, y] {
case .light:
isLighting = true
case .block:
isLighting = false
case .none:
break
}
if isLighting {
lightMap[x, y] = true
}
}
}
for x in map.xRange {
var isLighting = false
for y in map.yRange {
switch map[x, y] {
case .light:
isLighting = true
case .block:
isLighting = false
case .none:
break
}
if isLighting {
lightMap[x, y] = true
}
}
}
for x in map.xRange {
var isLighting = false
for y in map.yRange.reversed() {
switch map[x, y] {
case .light:
isLighting = true
case .block:
isLighting = false
case .none:
break
}
if isLighting {
lightMap[x, y] = true
}
}
}
let count = lightMap.reduce(into: 0) {
if $1 { $0 += 1 }
}
print(count)
提出情報
| 提出日時 |
|
| 問題 |
E - Akari |
| ユーザ |
koher |
| 言語 |
Swift (5.2.1) |
| 得点 |
500 |
| コード長 |
4422 Byte |
| 結果 |
AC |
| 実行時間 |
1319 ms |
| メモリ |
12724 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
handmade_00.txt, max_random_00.txt, max_random_01.txt, max_random_02.txt, max_random_03.txt, max_random_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt, surrounded_00.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| handmade_00.txt |
AC |
43 ms |
8008 KiB |
| max_random_00.txt |
AC |
1118 ms |
12432 KiB |
| max_random_01.txt |
AC |
1123 ms |
12264 KiB |
| max_random_02.txt |
AC |
1127 ms |
12672 KiB |
| max_random_03.txt |
AC |
1116 ms |
12672 KiB |
| max_random_04.txt |
AC |
1120 ms |
12724 KiB |
| random_00.txt |
AC |
1317 ms |
12260 KiB |
| random_01.txt |
AC |
1319 ms |
12656 KiB |
| random_02.txt |
AC |
10 ms |
8028 KiB |
| random_03.txt |
AC |
10 ms |
8024 KiB |
| random_04.txt |
AC |
1057 ms |
9440 KiB |
| random_05.txt |
AC |
517 ms |
11032 KiB |
| random_06.txt |
AC |
636 ms |
10324 KiB |
| random_07.txt |
AC |
1138 ms |
10824 KiB |
| random_08.txt |
AC |
120 ms |
8280 KiB |
| random_09.txt |
AC |
1048 ms |
9968 KiB |
| sample_01.txt |
AC |
5 ms |
8016 KiB |
| sample_02.txt |
AC |
5 ms |
8044 KiB |
| sample_03.txt |
AC |
6 ms |
8048 KiB |
| surrounded_00.txt |
AC |
1122 ms |
12656 KiB |