結果

問題 No.1200 お菓子配り-3
ユーザー yakamotoyakamoto
提出日時 2020-08-28 23:01:08
言語 Kotlin
(1.9.23)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,401 bytes
コンパイル時間 18,576 ms
コンパイル使用メモリ 463,368 KB
実行使用メモリ 77,664 KB
最終ジャッジ日時 2024-11-14 16:42:02
合計ジャッジ時間 36,512 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
54,172 KB
testcase_01 AC 284 ms
54,352 KB
testcase_02 AC 301 ms
54,404 KB
testcase_03 AC 308 ms
54,524 KB
testcase_04 AC 302 ms
54,216 KB
testcase_05 AC 300 ms
54,292 KB
testcase_06 AC 299 ms
54,308 KB
testcase_07 AC 308 ms
54,336 KB
testcase_08 AC 312 ms
54,248 KB
testcase_09 AC 310 ms
54,580 KB
testcase_10 AC 316 ms
54,348 KB
testcase_11 AC 310 ms
54,360 KB
testcase_12 AC 373 ms
56,604 KB
testcase_13 AC 377 ms
56,788 KB
testcase_14 AC 376 ms
56,820 KB
testcase_15 AC 373 ms
56,432 KB
testcase_16 AC 372 ms
56,572 KB
testcase_17 AC 621 ms
59,408 KB
testcase_18 AC 670 ms
61,492 KB
testcase_19 AC 390 ms
56,604 KB
testcase_20 AC 963 ms
66,368 KB
testcase_21 AC 957 ms
68,560 KB
testcase_22 AC 1,160 ms
70,100 KB
testcase_23 AC 1,073 ms
69,988 KB
testcase_24 AC 959 ms
66,564 KB
testcase_25 AC 953 ms
66,416 KB
testcase_26 AC 1,153 ms
77,664 KB
testcase_27 AC 286 ms
54,216 KB
testcase_28 AC 869 ms
63,512 KB
testcase_29 AC 1,419 ms
61,240 KB
testcase_30 AC 1,416 ms
61,228 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:151: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:155: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:159: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:163: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: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<IntArray>) {
          ^
Main.kt:187: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

fun divisors(x: Int): MutableList<Int> {
  val res = mutableListOf<Int>()
  var d = 1
  while (d * d <= x) {
    if (x % d == 0) {
      if (d > 0) res += d
      if (d * d != x) res += x / d
    }
    ++d
  }
  return res
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  fun solve() {
    for (i in 0 until ni()) {
      var x = nl()
      var y = nl()
      if (x < y) {
        val t = x
        x = y
        y = t
      }

      var ans = 0
      for (d in divisors((x - y).toInt())) {
        val a = (d + 1).toLong()
//        if (A.contains(a)) {
//          debug{"$a"}
          val plus = (x + y) / (a + 1)
          val minus = (x - y) / (a - 1)
          val bb = plus + minus
          if (bb <= 0 || bb and 1 == 1L) continue
          val b = bb shr 1
          val c = plus - b
          if (a <= 0 || b <= 0 || c <= 0) continue
          if (a * b + c == x && a * c + b == y) ans++
//        }
      }

      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 map(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 map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  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 { 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)
      }
    }
  }

  /**
   * 勝手に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