結果

問題 No.190 Dry Wet Moist
コンテスト
ユーザー norioc
提出日時 2016-02-16 15:34:36
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,630 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,813 ms
コンパイル使用メモリ 233,160 KB
最終ジャッジ日時 2026-03-09 14:38:25
合計ジャッジ時間 7,273 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E040] Syntax Error: Main.scala:65:32 ---------------------------------------
65 |  def main(args: Array[String]) {
   |                                ^
   |                                '=' expected, but '{' found
1 error found

ソースコード

diff #
raw source code

import math._
import scala.collection.mutable.ArrayBuffer

object Main {
  def moist(positives: Array[Int], negatives: Array[Int]): Int = {
    val ar = Array.fill(100001)(0)
    for (x <- negatives) {
      ar(abs(x)) += 1
    }

    var zero = 0
    var ans = 0
    for (x <- positives) {
      if (x == 0) {
        zero += 1
      }
      else {
        if (ar(x) > 0) {
          ans += 1
          ar(x) -= 1
        }
      }
    }
    ans + zero / 2
  }

  def wet(positives: Array[Int], negatives: Array[Int]): Int = {
    val xs = negatives ++ positives

    var ans = 0
    var lo = 0
    var hi = xs.length - 1
    while (lo < hi) {
      if (xs(lo) + xs(hi) > 0) {
        ans += 1
        lo += 1
        hi -= 1
      }
      else {
        lo += 1
      }
    }
    ans
  }

  def dry(positives: Array[Int], negatives: Array[Int]): Int = {
    val xs = negatives ++ positives

    var ans = 0
    var lo = 0
    var hi = xs.length - 1
    while (lo < hi) {
      if (xs(lo) + xs(hi) < 0) {
        ans += 1
        lo += 1
        hi -= 1
      }
      else {
        hi -= 1
      }
    }
    ans
  }

  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt

    val ps = new ArrayBuffer[Int]
    val ns = new ArrayBuffer[Int]
    for (i <- 1 to 2 * n) {
      val x = sc.nextInt
      if (x >= 0) ps.append(x)
      else ns.append(x)
    }

    val positives = ps.sorted.toArray
    val negatives = ns.sorted.toArray

    val d = dry(positives, negatives)
    val w = wet(positives, negatives)
    val m = moist(positives, negatives)
    println(s"$d $w $m")
  }
}
0