結果

問題 No.190 Dry Wet Moist
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2015-04-22 00:45:32
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,271 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 109,264 KB
実行使用メモリ 49,880 KB
最終ジャッジ日時 2023-09-18 06:21:04
合計ジャッジ時間 8,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 67 ms
23,980 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 218 ms
43,356 KB
testcase_23 WA -
testcase_24 AC 234 ms
49,880 KB
testcase_25 AC 67 ms
21,928 KB
testcase_26 AC 67 ms
21,836 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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);
        Array.Sort(A);
        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();
            var rem = 0;
            while (p < neg.Count && q < a.Length)
            {
                if (neg[p] > a[q])
                {
                    Console.WriteLine("{0} {1}", neg[p], a[q]);
                    dry++; p++; q++;
                }
                else { p++; rem++; }
            }
            dry += (neg.Count + rem - p) / 2;
        }
        {
            var p = 0;
            var q = 0;
            var a = zero.Concat(neg).ToArray();
            var rem = 0;
            while (p < pos.Count && q < a.Length)
            {
                if (pos[p] > a[q])
                {
                    wet++; p++; q++;
                }
                else { p++; rem++; }
            }
            wet += (pos.Count - p + rem) / 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;
    }
}
0