File tree Expand file tree Collapse file tree 2 files changed +8
-27
lines changed
Expand file tree Collapse file tree 2 files changed +8
-27
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 79516 KB, 시간: 12 ms
7+ 메모리: 69112 KB, 시간: 8 ms
88
99### 분류
1010
1111수학, 그리디 알고리즘, 정렬
1212
1313### 제출 일자
1414
15- 2025년 6월 13일 16:39:20
15+ 2025년 8월 28일 11:45:30
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1- import Foundation
2-
3- class FileIO {
4- @inline ( __always) private var buffer : [ UInt8 ] = Array ( FileHandle . standardInput. readDataToEndOfFile ( ) ) + [ 0 ] , byteIdx = 0
5-
6- @inline ( __always) private func readByte( ) -> UInt8 {
7- defer { byteIdx += 1 }
8- return buffer. withUnsafeBufferPointer { $0 [ byteIdx] }
9- }
10-
11- @inline ( __always) func readInt( ) -> Int {
12- var number = 0 , byte = readByte ( ) , isNegative = false
13- while byte == 10 || byte == 32 { byte = readByte ( ) }
14- if byte == 45 { byte = readByte ( ) ; isNegative = true }
15- while 48 ... 57 ~= byte { number = number * 10 + Int( byte - 48 ) ; byte = readByte ( ) }
16- return number * ( isNegative ? - 1 : 1 )
17- }
1+ let n = Int ( readLine ( ) !) !
2+ let a = readLine ( ) !. split { $0 == " " } . map { Int ( String ( $0) ) ! } . sorted { $0 < $1 }
3+ let b = readLine ( ) !. split { $0 == " " } . map { Int ( String ( $0) ) ! } . sorted { $0 > $1 }
4+ var answer = 0
5+ for i in 0 ..< n {
6+ answer += a [ i] * b[ i]
187}
19-
20- let io = FileIO ( )
21- let n = io. readInt ( )
22- let aList = ( 0 ..< n) . map { _ in io. readInt ( ) } . sorted { $0 < $1 }
23- let bList = ( 0 ..< n) . map { _ in io. readInt ( ) } . sorted { $0 > $1 }
24-
25- let answer = zip ( aList, bList) . map { a, b in a*b } . reduce ( 0 , + )
26-
278print ( answer)
You can’t perform that action at this time.
0 commit comments