Submission #5025086
Source Code Expand
object Main {
def main(args: Array[String]): Unit = {
val s = new Main()
s.solve()
s.out.flush()
}
}
class Main {
import java.io._
import java.util.StringTokenizer
import java.util.Arrays.sort
import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag
val MOD = 1000000007
val out = new PrintWriter(System.out)
def solve(): Unit = {
val N = ni() - 1 // 移動回数
val A, B, C, D = ni()
val X = B - A
case class Range(l: Long, r: Long)
def find(n: Int, d: Long, rg: Range): Boolean = {
debug(s"find($n) d:$d rg:$rg")
REP(n) { i =>
val l = rg.l + d * i
val r = rg.r + d * i
// debug(s"l:$l r:$r")
if (l <= X && X <= r) return true
}
false
}
val ok = if (N % 2 == 0) {
val len = (D - C).toLong * N / 2
val d = C + D
val rg = Range(-len, len)
find(N / 2 + 1, d, rg) || find(N / 2 + 1, -d, rg)
} else {
val len = (D - C).toLong * (N - 1) / 2
val d = C + D
find(N / 2 + 1, d, Range(C - len, D + len)) || find(N / 2 + 1, -d, Range(-D - len, -C + len))
}
if (ok) out.println("YES")
else out.println("NO")
}
private val oj = System.getenv("ATCODER_DEBUG") == null
def DEBUG(f: => Unit): Unit = {
if (!oj){ f }
}
def debug(as: Array[Boolean]): Unit = DEBUG {
debug(as.map(x => if(x) "1" else "0").mkString)
}
def debug(as: Array[Int]): Unit = DEBUG {
debug(as.mkString(" "))
}
def debug(as: Array[Long]): Unit = DEBUG {
debug(as.mkString(" "))
}
def debug(s: => String): Unit = DEBUG {
System.err.println(s)
}
def debugL(num: => Long): Unit = DEBUG {
System.err.println(num)
}
class InputReader(val stream: InputStream) {
private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
private var tokenizer: StringTokenizer = _
def next(): String = {
while (tokenizer == null || !tokenizer.hasMoreTokens)
tokenizer = new StringTokenizer(reader.readLine)
tokenizer.nextToken
}
def nextInt(): Int = next().toInt
def nextLong(): Long = next().toLong
def nextChar(): Char = next().charAt(0)
}
val sc = new InputReader(System.in)
def ni(): Int = sc.nextInt()
def nl(): Long = sc.nextLong()
def nc(): Char = sc.nextChar()
def ns(): String = sc.next()
def ns(n: Int): Array[Char] = ns().toCharArray
def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
val A1, A2 = Array.ofDim[Int](n)
REP(n) { i =>
A1(i) = ni() + offset
A2(i) = ni() + offset
}
(A1, A2)
}
def nm(n: Int, m: Int): Array[Array[Int]] = {
val A = Array.ofDim[Int](n, m)
REP(n) { i =>
REP(m) { j =>
A(i)(j) = ni()
}
}
A
}
def nal(n: Int): Array[Long] = map(n)(_ => nl())
def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
var i = offset
val N = n + offset
while(i < N) { f(i); i += 1 }
}
def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
var i = n - 1 + offset
while(i >= offset) { f(i); i -= 1 }
}
def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
REP(to - from + 1, from) { i =>
f(i)
}
}
def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
val res = Array.ofDim[A](n)
REP(n)(i => res(i) = f(i + offset))
res
}
def sumL(as: Array[Int]): Long = {
var s = 0L
REP(as.length)(i => s += as(i))
s
}
def cumSum(as: Array[Int]) = {
val cum = Array.ofDim[Long](as.length + 1)
REP(as.length) { i =>
cum(i + 1) = cum(i) + as(i)
}
cum
}
}
Submission Info
Submission Time |
|
Task |
B - Moderate Differences |
User |
yakamoto |
Language |
Scala (2.11.7) |
Score |
400 |
Code Size |
4054 Byte |
Status |
AC |
Exec Time |
368 ms |
Memory |
27328 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt, sample4.txt |
All |
sample1.txt, sample2.txt, sample3.txt, sample4.txt, a01.txt, a02.txt, a03.txt, a04.txt, b01.txt, b02.txt, b03.txt, b04.txt, c01.txt, c02.txt, c03.txt, c04.txt, d01.txt, d02.txt, d03.txt, d04.txt, d05.txt, d06.txt, d07.txt, d08.txt, d09.txt, d10.txt, d11.txt, d12.txt, d13.txt, d14.txt, d15.txt, d16.txt, d17.txt, d18.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt |
Case Name |
Status |
Exec Time |
Memory |
a01.txt |
AC |
327 ms |
25260 KB |
a02.txt |
AC |
333 ms |
25272 KB |
a03.txt |
AC |
335 ms |
25400 KB |
a04.txt |
AC |
340 ms |
25416 KB |
b01.txt |
AC |
345 ms |
25288 KB |
b02.txt |
AC |
348 ms |
25424 KB |
b03.txt |
AC |
350 ms |
25388 KB |
b04.txt |
AC |
343 ms |
25412 KB |
c01.txt |
AC |
349 ms |
25276 KB |
c02.txt |
AC |
342 ms |
23468 KB |
c03.txt |
AC |
344 ms |
25016 KB |
c04.txt |
AC |
352 ms |
25388 KB |
d01.txt |
AC |
342 ms |
25284 KB |
d02.txt |
AC |
333 ms |
25292 KB |
d03.txt |
AC |
349 ms |
25556 KB |
d04.txt |
AC |
352 ms |
25280 KB |
d05.txt |
AC |
347 ms |
25512 KB |
d06.txt |
AC |
331 ms |
25276 KB |
d07.txt |
AC |
329 ms |
25272 KB |
d08.txt |
AC |
350 ms |
25420 KB |
d09.txt |
AC |
342 ms |
27328 KB |
d10.txt |
AC |
352 ms |
23596 KB |
d11.txt |
AC |
328 ms |
25256 KB |
d12.txt |
AC |
347 ms |
25292 KB |
d13.txt |
AC |
331 ms |
25152 KB |
d14.txt |
AC |
349 ms |
25292 KB |
d15.txt |
AC |
351 ms |
25272 KB |
d16.txt |
AC |
348 ms |
25280 KB |
d17.txt |
AC |
337 ms |
25252 KB |
d18.txt |
AC |
368 ms |
25408 KB |
sample1.txt |
AC |
332 ms |
25376 KB |
sample2.txt |
AC |
340 ms |
25412 KB |
sample3.txt |
AC |
340 ms |
25416 KB |
sample4.txt |
AC |
331 ms |
23460 KB |