結果

問題 No.1709 Indistinguishable by MEX
ユーザー ripityripity
提出日時 2022-07-05 19:02:00
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 4,209 bytes
コンパイル時間 16,788 ms
コンパイル使用メモリ 452,928 KB
実行使用メモリ 67,364 KB
最終ジャッジ日時 2024-05-09 14:11:24
合計ジャッジ時間 27,078 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
49,840 KB
testcase_01 AC 264 ms
49,800 KB
testcase_02 AC 270 ms
50,152 KB
testcase_03 AC 268 ms
50,144 KB
testcase_04 AC 267 ms
50,044 KB
testcase_05 AC 272 ms
50,128 KB
testcase_06 AC 269 ms
49,996 KB
testcase_07 AC 268 ms
50,156 KB
testcase_08 AC 434 ms
62,956 KB
testcase_09 AC 426 ms
61,032 KB
testcase_10 AC 403 ms
60,724 KB
testcase_11 AC 412 ms
59,200 KB
testcase_12 AC 415 ms
58,964 KB
testcase_13 AC 424 ms
62,144 KB
testcase_14 AC 414 ms
61,344 KB
testcase_15 AC 422 ms
61,720 KB
testcase_16 AC 447 ms
66,684 KB
testcase_17 AC 456 ms
65,788 KB
testcase_18 AC 458 ms
67,236 KB
testcase_19 AC 455 ms
67,240 KB
testcase_20 AC 459 ms
67,364 KB
testcase_21 AC 449 ms
67,204 KB
testcase_22 AC 443 ms
67,312 KB
testcase_23 AC 433 ms
67,120 KB
testcase_24 AC 446 ms
67,304 KB
testcase_25 AC 443 ms
67,288 KB
testcase_26 AC 269 ms
49,896 KB
testcase_27 AC 436 ms
59,624 KB
testcase_28 AC 415 ms
59,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun main() {
    
    // val T = nextInt()
    // repeat(T) {solve()}
    // pw.flush()
    
    solve()
    pw.flush()
    
}

fun solve() {
    
    val P = 998244353L
    
    val N = nextInt()
    val p = nextIntarr(N)
    val ip = permInv(p)
    var l = N
    var r = -1
    var ans = 1L
    
    for( i in 0 until N ) {
        l = min(l, ip[i])
        r = max(r, ip[i])
        if( l != ip[i] && r != ip[i] ) {
            ans *= (r-l+1)-i
            ans %= P
        }
    }
    
    pw.println(ans)
    
}

/* struct begin */

data class Cell(val r: Int, val c: Int)
data class Point(val x: Long, val y: Long)
data class Pii(val fi: Int, val se: Int)
data class Edge(val to: Int, val w: Long)

class BinaryIndexedTree(n: Int) {
    
    val N = n
    var a = Array<Long>(N+1) { 0L }
    
    fun sum(l: Int, r: Int): Long = sumSub(r-1)-sumSub(l-1)
    
    fun sumSub(i: Int): Long {
        
        var idx = i+1
        var res = 0L
        while( idx > 0 ) {
            res += a[idx]
            idx -= idx and (-idx)
        }
        
        return res
        
    }
    
    fun add(i: Int, x: Long) {
        
        var idx = i+1
        while( idx <= N ) {
            a[idx] += x
            idx += idx and (-idx)
        }
        
    }
    
}

class UnionFind(n: Int) {
    
    val N = n
    var parent = Array<Int>(N) {it}
    var rank = Array<Int>(N) {1}
    
    fun root(x: Int): Int {
        
        if( parent[x] == x ) {
            return x
        }else {
            parent[x] = root(parent[x])
            return parent[x]
        }
        
    }
    
    fun unite(x: Int, y: Int) {
        
        val rx = root(x)
        val ry = root(y)
        parent[ry] = rx
        
    }
    
    fun same(x: Int, y: Int): Boolean = (root(x) == root(y))
    
}

/* struct end */

/* math begin */

fun intceil(x: Double) = ceil(x).toInt()
fun intfloor(x: Double) = floor(x).toInt()
fun gcd(x: Long, y: Long): Long {
    
    var a = max(abs(x), abs(y))
    var b = min(abs(x), abs(y))
    var r: Long
    
    do {
        r = a%b
        a = b
        b = r
    }while( r > 0 )
    
    return a
    
}

fun modpow(X: Long, T: Long, P: Long = 9223372036854775807L): Long {
    
    var x = X
    var t = T
    
    if( t == 0L ) {
        return 1L
    }else {
        var res = 1L
        while( t > 0 ) {
            if( t%2L == 1L ) {
                res *= x
                res %= P
                t -= 1L
            }
            x *= x
            x %= P
            t /= 2
        }
        return res%P
    }
    
}

/* math end */

/* utility begin */

fun cumulativeSum(a: LongArray): LongArray {
    
    val N = a.size
    var s = LongArray(N+1) { 0L }
    
    for( i in 1..N ) {
        s[i] = s[i-1]+a[i-1]
    }
    
    return s
    
}

fun rlowerBound(a: LongArray, x: Long): Int {
    
    val N = a.size
    var high = N-1
    var low = 0
    var mid: Int
    
    while( low < high ) {
        mid = (high+low+1)/2
        if( a[mid] > x ) high = mid-1
        else low = high
    }
    
    return high
    
}

fun lowerBound(a: LongArray, x: Long): Int {
    
    val N = a.size
    var high = N-1
    var low = 0
    var mid: Int
    
    while( low < high ) {
        mid = (high+low)/2
        if( a[mid] < x ) low = mid+1
        else high = mid
    }
    
    return low
    
}

fun permInv(p: IntArray): IntArray {
    
    val N = p.size
    var res = IntArray(N) { -1 }
    
    for( i in 0 until N ) {
        res[p[i]] = i
    }
    
    return res
    
}

/* utility end */

/* I/O begin */

var st = StringTokenizer("")
val br = System.`in`.bufferedReader()
val pw = PrintWriter(System.out, false)

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()!!
fun nextDouble() = next().toDouble()
fun nextStrarr(n: Int) = Array<String>(n) { next() }
fun nextIntarr(n: Int, dec: Int = 0) = IntArray(n) { nextInt()-dec }
fun nextLongarr(n: Int, dec: Long = 0L) = LongArray(n) { nextLong()-dec }

fun next(): String {
    
    while( !st.hasMoreTokens() ) st = StringTokenizer(br.readLine()!!)
    return st.nextToken()
    
}

/* I/O end */
0