結果

問題 No.1233 割り切れない気持ち
ユーザー yakamotoyakamoto
提出日時 2020-09-22 19:57:23
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 543 ms / 3,153 ms
コード長 3,505 bytes
コンパイル時間 15,051 ms
コンパイル使用メモリ 454,844 KB
実行使用メモリ 74,364 KB
最終ジャッジ日時 2024-06-26 10:15:13
合計ジャッジ時間 35,843 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
57,776 KB
testcase_01 AC 295 ms
57,888 KB
testcase_02 AC 316 ms
57,752 KB
testcase_03 AC 310 ms
57,884 KB
testcase_04 AC 321 ms
58,020 KB
testcase_05 AC 304 ms
57,936 KB
testcase_06 AC 304 ms
57,892 KB
testcase_07 AC 479 ms
62,884 KB
testcase_08 AC 487 ms
64,936 KB
testcase_09 AC 543 ms
71,004 KB
testcase_10 AC 503 ms
72,796 KB
testcase_11 AC 446 ms
62,216 KB
testcase_12 AC 506 ms
74,272 KB
testcase_13 AC 507 ms
74,280 KB
testcase_14 AC 504 ms
74,072 KB
testcase_15 AC 513 ms
74,100 KB
testcase_16 AC 521 ms
74,268 KB
testcase_17 AC 448 ms
70,276 KB
testcase_18 AC 514 ms
74,364 KB
testcase_19 AC 464 ms
74,172 KB
testcase_20 AC 445 ms
70,216 KB
testcase_21 AC 446 ms
71,704 KB
testcase_22 AC 442 ms
71,680 KB
testcase_23 AC 470 ms
71,532 KB
testcase_24 AC 449 ms
71,580 KB
testcase_25 AC 445 ms
71,940 KB
testcase_26 AC 450 ms
71,740 KB
testcase_27 AC 451 ms
71,924 KB
testcase_28 AC 476 ms
72,328 KB
testcase_29 AC 469 ms
72,468 KB
testcase_30 AC 456 ms
71,936 KB
testcase_31 AC 457 ms
71,860 KB
testcase_32 AC 458 ms
71,764 KB
testcase_33 AC 479 ms
71,736 KB
testcase_34 AC 453 ms
71,716 KB
testcase_35 AC 448 ms
72,160 KB
testcase_36 AC 454 ms
71,760 KB
testcase_37 AC 294 ms
57,876 KB
testcase_38 AC 435 ms
70,280 KB
testcase_39 AC 460 ms
71,576 KB
testcase_40 AC 451 ms
71,504 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:156:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: LongArray) {
          ^
Main.kt:160:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: IntArray) {
          ^
Main.kt:164:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: BooleanArray) {
          ^
Main.kt:168:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")}
          ^
Main.kt:170:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<LongArray>) {
          ^
Main.kt:177:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<IntArray>) {
          ^
Main.kt:184:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<BooleanArray>) {
          ^
Main.kt:201:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}
          ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.AssertionError
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007

class LinearFunctionComposition(val N: Int) {

  private val c0 = LongArray(N)
  private val c1 = LongArray(N)

  /**
   * @param s f(l)の値
   */
  fun add(l: Int, r: Int, delta: Long, s: Long) {
    c1[l] += delta
    c1[r] -= delta
    c0[l] += s - l * delta
    c0[r] -= s - l * delta
  }

  fun build() {
    for (i in 0 until N - 1) {
      c0[i + 1] += c0[i]
      c1[i + 1] += c1[i]
    }
  }

  fun calc(x: Int): Long {
    return c1[x] * x + c0[x]
  }
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  private val reader = BufferedReader(InputStreamReader(stream), 32768)

  val MAX = 200_000
  private val N = ni()
  private val A = na(N)
  private val Acnt = LongArray(MAX + 100)
  init {
    for (a in A) {
      Acnt[a]++
    }
  }
  fun solve() {
    val fn = LinearFunctionComposition(2*MAX + 100)
    for (b in 2 .. MAX) {
      if (Acnt[b] == 0L) continue
      var a = 0
      while(a <= MAX) {
        fn.add(a, a + b, Acnt[b], 0)
        a += b
      }
    }
    fn.build()

    var ans = 0L
    for (a in A) {
      ans += fn.calc(a)
    }
    out.println(ans)
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return IntArray(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private inline fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private inline fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private inline fun debug(a: BooleanArray) {
    debug { toString(a) }
  }

  private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")}

  private inline fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<BooleanArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }

  private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}
0