結果

問題 No.1988 Divisor Tiling
ユーザー ripityripity
提出日時 2022-06-28 15:02:33
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 3,736 bytes
コンパイル時間 14,862 ms
コンパイル使用メモリ 450,580 KB
実行使用メモリ 56,976 KB
最終ジャッジ日時 2024-05-01 06:07:54
合計ジャッジ時間 26,858 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
54,268 KB
testcase_01 AC 255 ms
54,312 KB
testcase_02 AC 251 ms
54,316 KB
testcase_03 AC 252 ms
54,252 KB
testcase_04 AC 253 ms
54,232 KB
testcase_05 AC 250 ms
54,272 KB
testcase_06 AC 252 ms
54,348 KB
testcase_07 AC 258 ms
54,268 KB
testcase_08 AC 265 ms
54,452 KB
testcase_09 AC 260 ms
54,328 KB
testcase_10 AC 265 ms
54,444 KB
testcase_11 AC 260 ms
54,412 KB
testcase_12 AC 270 ms
54,320 KB
testcase_13 AC 267 ms
54,576 KB
testcase_14 AC 257 ms
54,308 KB
testcase_15 AC 261 ms
54,364 KB
testcase_16 AC 258 ms
54,376 KB
testcase_17 AC 255 ms
54,444 KB
testcase_18 AC 332 ms
56,976 KB
testcase_19 AC 338 ms
56,828 KB
testcase_20 AC 319 ms
56,776 KB
testcase_21 AC 348 ms
56,768 KB
testcase_22 AC 330 ms
56,784 KB
testcase_23 AC 330 ms
56,660 KB
testcase_24 AC 335 ms
56,780 KB
testcase_25 AC 332 ms
56,836 KB
testcase_26 AC 345 ms
56,788 KB
testcase_27 AC 393 ms
56,792 KB
testcase_28 AC 325 ms
56,680 KB
testcase_29 AC 335 ms
56,684 KB
testcase_30 AC 334 ms
56,828 KB
testcase_31 AC 347 ms
56,656 KB
testcase_32 AC 258 ms
54,408 KB
testcase_33 AC 254 ms
54,416 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 N = nextInt()
    val h = nextInt()
    val w = N/h
    val H = min(h, w)
    val W = max(h, w)
    var x = Array(H) { IntArray(W) { -1 } }
    
    val d = when(N) {
        6 -> arrayOf(1, 2, 3)
        28 -> arrayOf(1, 2, 4, 7, 14)
        496 -> arrayOf(1, 2, 4, 8, 16, 31, 62, 124, 248)
        else -> arrayOf(1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064)
    }
    var cnt = 0
    var k = d.size-1
    
    for( i in 0 until H ) {
        for( j in 0 until W ) {
            if( cnt == d[k] ) { cnt = 0; k-- }
            cnt++
            x[i][j] = d[k]
        }
    }
    
    for( i in 0 until h ) {
        for( j in 0 until w ) {
            val ans = if( H == h ) x[i][j] else x[j][i]
            pw.print("$ans ")
        }
        pw.println()
    }
    
}

/* 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(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)
        if( rx == ry ) return
        
        if( rank[rx] > rank[ry] ) {
            parent[ry] = rx
        }else {
            parent[rx] = ry
            if( rank[rx] == rank[ry] ) rank[ry]++
        }
        
    }
    
    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 */

/* 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 nextIntarr(n: Int) = Array<Int>(n) {nextInt()}
fun nextStrarr(n: Int) = Array<String>(n) {next()}
fun nextLongarr(n: Int) = Array<Long>(n) {nextLong()}

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

/* I/O end */
0