結果
| 問題 |
No.190 Dry Wet Moist
|
| コンテスト | |
| ユーザー |
紙ぺーぱー
|
| 提出日時 | 2015-04-20 21:37:46 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,100 bytes |
| コンパイル時間 | 2,072 ms |
| コンパイル使用メモリ | 115,244 KB |
| 実行使用メモリ | 43,136 KB |
| 最終ジャッジ日時 | 2024-07-04 18:45:11 |
| 合計ジャッジ時間 | 5,523 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 WA * 13 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
static public class Program
{
static public void Main()
{
var n = readInteger().Validate(x => 1 <= x && x <= 100000);
var A = readInteger(2 * n).ValidateArray(x => -100000 <= x && x <= 100000);
readEOF();
var neg = new List<int>();
var pos = new List<int>();
var zero = new List<int>();
foreach (var x in A)
if (x > 0) pos.Add(x);
else if (x == 0) zero.Add(x);
else neg.Add(-x);
neg.Sort();
pos.Sort();
int dry = 0, wet = 0, moist = 0;
{
var p = 0;
var q = 0;
var a = zero.Concat(pos).ToArray();
while (p < neg.Count && q < a.Length)
{
if (neg[p] > a[q])
{
dry++; p++; q++;
}
else p++;
}
dry += (neg.Count - p) / 2;
}
{
var p = 0;
var q = 0;
var a = zero.Concat(neg).ToArray();
while (p < pos.Count && q < a.Length)
{
if (pos[p] > a[q])
{
wet++; p++; q++;
}
else p++;
}
wet += (pos.Count - p) / 2;
}
{
var p = 0;
var q = 0;
while (p < pos.Count && q < neg.Count)
{
if (pos[p] > neg[q]) q++;
else if (pos[p] < neg[q]) p++;
else { moist++; p++; q++; }
}
moist += zero.Count / 2;
}
Console.WriteLine("{0} {1} {2}", dry, wet, moist);
}
static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
static int readInteger()
{
var s = Console.ReadLine();
return int.Parse(s);
}
static int[] readInteger(int n)
{
var s = Console.ReadLine().Split(' ');
if (s.Length != n)
throw new Exception(string.Format("invalid input, expected{0} actual{1}", n, s.Length));
var ret = new int[n];
for (int i = 0; i < n; i++)
ret[i] = int.Parse(s[i]);
return ret;
}
static string[] readString(int n)
{
var s = Console.ReadLine().Split(' ');
if (s.Length != n)
throw new Exception(string.Format("invalid input, expected{0} actual{1}", n, s.Length));
return s;
}
static void readEOF()
{
if (Console.In.Peek() >= 0)
throw new Exception("invalid input too long input file");
}
}
static public class Ex
{
static public T Validate<T>(this T input, Func<T, bool> f)
{
if (!f(input))
throw new Exception("invalid input");
return input;
}
static public T[] ValidateArray<T>(this T[] input, Func<T, bool> f)
{
foreach (var x in input)
if (!f(x))
throw new Exception("invalid input");
return input;
}
}
紙ぺーぱー