結果

問題 No.110 しましまピラミッド
ユーザー バカらっくバカらっく
提出日時 2018-06-11 17:22:54
言語 Swift
(5.10.0)
結果
TLE  
実行時間 -
コード長 1,206 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 132,796 KB
実行使用メモリ 16,372 KB
最終ジャッジ日時 2023-08-20 10:48:49
合計ジャッジ時間 14,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Proc {
    let blackBlock:[Int]
    let whiteBlock:[Int]
    init() {
        _ = readLine()!
        self.whiteBlock = readLine()!.split(separator: " ").map{ Int($0)!}.sorted()
        _ = readLine()!
        self.blackBlock = readLine()!.split(separator: " ").map{ Int($0)! }.sorted()
    }
    public func doProc() {
        var ans = GetAns(idx: blackBlock.count - 1, isBlack: true)
        ans = max(ans, GetAns(idx: whiteBlock.count-1, isBlack: false))
        print(ans)
    }

    private func GetAns(idx:Int, isBlack:Bool) -> Int {
        let currentLen = isBlack ? self.blackBlock[idx] : self.whiteBlock[idx]

        var next = -1

        if isBlack {
            for i in 0..<whiteBlock.count {
                if whiteBlock[i] > currentLen {
                    break
                }
                next = i
            }
        } else {
            for i in 0..<blackBlock.count {
                if blackBlock[i] > currentLen {
                    break
                }
                next = i
            }
        }

        if next < 0 {
            return 1
        }
        let ans = GetAns(idx: next, isBlack: !isBlack) + 1
        return ans
    }
}

Proc().doProc()
0