結果
問題 | No.1557 Binary Variable |
ユーザー |
|
提出日時 | 2021-06-25 22:32:36 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 955 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 12,195 ms |
コンパイル使用メモリ | 440,088 KB |
実行使用メモリ | 94,332 KB |
最終ジャッジ日時 | 2024-06-25 08:37:32 |
合計ジャッジ時間 | 44,548 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
import java.io.PrintWriterimport java.lang.Exceptionimport java.util.*fun PrintWriter.solve() {val n = nextInt()val m = nextInt()val segs = mutableListOf<Pair<Int, Int>>()for (i in 0 until m) {val l = nextInt()val r = nextInt()segs.add(l to r)}segs.sortBy { it.second }var count = 0var prev = -1for ((l, r) in segs) {if (prev in l..r) continuecount++prev = r}println(n - count)}fun main() {val writer = PrintWriter(System.out, false)writer.solve()writer.flush()}// region Scannerprivate var st = StringTokenizer("")private val br = System.`in`.bufferedReader()fun next(): String {while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())return st.nextToken()}fun nextInt() = next().toInt()fun nextLong() = next().toLong()fun nextLine() = br.readLine()fun nextDouble() = next().toDouble()// endregion