結果

問題 No.2267 群の公理
ユーザー 👑 箱
提出日時 2023-03-10 02:39:27
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,640 bytes
コンパイル時間 12,391 ms
コンパイル使用メモリ 438,920 KB
実行使用メモリ 50,372 KB
最終ジャッジ日時 2024-04-18 18:20:30
合計ジャッジ時間 28,224 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
50,036 KB
testcase_01 AC 284 ms
50,108 KB
testcase_02 AC 279 ms
50,204 KB
testcase_03 AC 288 ms
50,164 KB
testcase_04 AC 277 ms
50,212 KB
testcase_05 AC 282 ms
49,872 KB
testcase_06 AC 282 ms
49,976 KB
testcase_07 AC 278 ms
49,896 KB
testcase_08 AC 280 ms
50,156 KB
testcase_09 AC 292 ms
50,192 KB
testcase_10 AC 285 ms
50,036 KB
testcase_11 AC 282 ms
49,864 KB
testcase_12 AC 290 ms
49,944 KB
testcase_13 AC 280 ms
50,112 KB
testcase_14 AC 285 ms
49,964 KB
testcase_15 AC 283 ms
50,240 KB
testcase_16 AC 284 ms
49,940 KB
testcase_17 AC 282 ms
49,952 KB
testcase_18 AC 283 ms
50,132 KB
testcase_19 AC 285 ms
50,012 KB
testcase_20 AC 313 ms
50,076 KB
testcase_21 AC 295 ms
50,140 KB
testcase_22 AC 281 ms
50,040 KB
testcase_23 AC 288 ms
50,156 KB
testcase_24 AC 279 ms
50,092 KB
testcase_25 AC 289 ms
50,084 KB
testcase_26 AC 283 ms
49,968 KB
testcase_27 AC 280 ms
50,176 KB
testcase_28 AC 284 ms
50,136 KB
testcase_29 AC 287 ms
50,112 KB
testcase_30 AC 286 ms
50,080 KB
testcase_31 AC 284 ms
50,332 KB
testcase_32 AC 291 ms
50,204 KB
testcase_33 AC 287 ms
49,932 KB
testcase_34 AC 287 ms
50,044 KB
testcase_35 AC 289 ms
50,160 KB
testcase_36 AC 284 ms
50,148 KB
testcase_37 AC 284 ms
50,184 KB
testcase_38 AC 293 ms
50,364 KB
testcase_39 AC 289 ms
49,968 KB
testcase_40 AC 282 ms
50,240 KB
testcase_41 AC 288 ms
50,048 KB
testcase_42 AC 292 ms
50,220 KB
testcase_43 AC 289 ms
50,052 KB
testcase_44 AC 289 ms
50,196 KB
testcase_45 AC 293 ms
50,188 KB
testcase_46 AC 291 ms
50,372 KB
testcase_47 AC 300 ms
50,276 KB
testcase_48 AC 289 ms
50,052 KB
testcase_49 AC 290 ms
50,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val t = Array(n) { Array(n) { nextInt() } }
    for (i in 0 until n) {
        for (j in 0 until n) {
            for (k in 0 until n) {
                if (t[t[i][j]][k] != t[i][t[j][k]]) {
                    println("No")
                    return
                }
            }
        }
    }
    var e = -1
    loop@for (i in 0 until n) {
        for (j in 0 until n) {
            if (t[i][j] != j) {
                continue@loop
            }
        }
        e = i
        break
    }
    if (e == -1) {
        println("No")
        return
    }
    for (i in 0 until n) {
        var ok = false
        for (j in 0 until n) {
            if (t[j][i] == e) {
                ok = true
                break
            }
        }
        if (!ok) {
            println("No")
            return
        }
    }
    println("Yes")
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private 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
0