結果
問題 | No.190 Dry Wet Moist |
ユーザー |
![]() |
提出日時 | 2016-02-16 15:34:36 |
言語 | Scala(Beta) (3.6.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,630 bytes |
コンパイル時間 | 6,104 ms |
コンパイル使用メモリ | 229,036 KB |
最終ジャッジ日時 | 2024-11-14 19:34:08 |
合計ジャッジ時間 | 6,740 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[31m[31m-- [E040] Syntax Error: Main.scala:65:32 ---------------------------------------[0m[0m [31m65 |[0m [33mdef[0m [36mmain[0m([36margs[0m: [35mArray[0m[[35mString[0m]) { [31m[31m |[0m ^[0m [31m |[0m '=' expected, but '{' found 1 error found
ソースコード
import math._import scala.collection.mutable.ArrayBufferobject 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 = 0var ans = 0for (x <- positives) {if (x == 0) {zero += 1}else {if (ar(x) > 0) {ans += 1ar(x) -= 1}}}ans + zero / 2}def wet(positives: Array[Int], negatives: Array[Int]): Int = {val xs = negatives ++ positivesvar ans = 0var lo = 0var hi = xs.length - 1while (lo < hi) {if (xs(lo) + xs(hi) > 0) {ans += 1lo += 1hi -= 1}else {lo += 1}}ans}def dry(positives: Array[Int], negatives: Array[Int]): Int = {val xs = negatives ++ positivesvar ans = 0var lo = 0var hi = xs.length - 1while (lo < hi) {if (xs(lo) + xs(hi) < 0) {ans += 1lo += 1hi -= 1}else {hi -= 1}}ans}def main(args: Array[String]) {val sc = new java.util.Scanner(System.in)val n = sc.nextIntval ps = new ArrayBuffer[Int]val ns = new ArrayBuffer[Int]for (i <- 1 to 2 * n) {val x = sc.nextIntif (x >= 0) ps.append(x)else ns.append(x)}val positives = ps.sorted.toArrayval negatives = ns.sorted.toArrayval d = dry(positives, negatives)val w = wet(positives, negatives)val m = moist(positives, negatives)println(s"$d $w $m")}}