結果

問題 No.190 Dry Wet Moist
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2015-04-22 00:46:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 3,273 bytes
コンパイル時間 3,084 ms
コンパイル使用メモリ 109,260 KB
実行使用メモリ 47,016 KB
最終ジャッジ日時 2023-09-18 06:27:52
合計ジャッジ時間 7,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,924 KB
testcase_01 AC 66 ms
21,744 KB
testcase_02 AC 64 ms
21,808 KB
testcase_03 AC 66 ms
21,744 KB
testcase_04 AC 65 ms
19,788 KB
testcase_05 AC 65 ms
21,904 KB
testcase_06 AC 66 ms
21,808 KB
testcase_07 AC 75 ms
24,204 KB
testcase_08 AC 74 ms
24,188 KB
testcase_09 AC 74 ms
26,140 KB
testcase_10 AC 73 ms
22,172 KB
testcase_11 AC 73 ms
24,100 KB
testcase_12 AC 140 ms
32,276 KB
testcase_13 AC 167 ms
38,148 KB
testcase_14 AC 137 ms
32,132 KB
testcase_15 AC 174 ms
40,772 KB
testcase_16 AC 202 ms
40,220 KB
testcase_17 AC 87 ms
23,092 KB
testcase_18 AC 126 ms
30,700 KB
testcase_19 AC 199 ms
40,176 KB
testcase_20 AC 162 ms
39,268 KB
testcase_21 AC 82 ms
22,956 KB
testcase_22 AC 216 ms
41,396 KB
testcase_23 AC 231 ms
47,016 KB
testcase_24 AC 232 ms
45,932 KB
testcase_25 AC 67 ms
22,000 KB
testcase_26 AC 67 ms
23,844 KB
testcase_27 AC 174 ms
39,228 KB
testcase_28 AC 112 ms
25,128 KB
testcase_29 AC 124 ms
28,668 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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