結果

問題 No.1265 Balloon Survival
ユーザー g4np0n_kyoprog4np0n_kyopro
提出日時 2020-10-23 23:55:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 653 ms / 2,000 ms
コード長 10,347 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 67,132 KB
実行使用メモリ 67,416 KB
最終ジャッジ日時 2023-09-28 19:15:30
合計ジャッジ時間 12,272 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
20,932 KB
testcase_01 AC 81 ms
23,080 KB
testcase_02 AC 74 ms
22,976 KB
testcase_03 AC 81 ms
25,032 KB
testcase_04 AC 80 ms
22,852 KB
testcase_05 AC 81 ms
24,908 KB
testcase_06 AC 81 ms
22,940 KB
testcase_07 AC 79 ms
22,980 KB
testcase_08 AC 80 ms
23,024 KB
testcase_09 AC 80 ms
22,904 KB
testcase_10 AC 79 ms
22,988 KB
testcase_11 AC 79 ms
22,868 KB
testcase_12 AC 81 ms
23,004 KB
testcase_13 AC 82 ms
24,908 KB
testcase_14 AC 139 ms
32,616 KB
testcase_15 AC 124 ms
30,308 KB
testcase_16 AC 96 ms
25,388 KB
testcase_17 AC 365 ms
49,928 KB
testcase_18 AC 102 ms
27,740 KB
testcase_19 AC 97 ms
25,580 KB
testcase_20 AC 135 ms
30,528 KB
testcase_21 AC 215 ms
36,144 KB
testcase_22 AC 162 ms
33,076 KB
testcase_23 AC 171 ms
33,364 KB
testcase_24 AC 645 ms
63,296 KB
testcase_25 AC 647 ms
65,348 KB
testcase_26 AC 653 ms
65,396 KB
testcase_27 AC 636 ms
65,504 KB
testcase_28 AC 638 ms
65,384 KB
testcase_29 AC 644 ms
61,456 KB
testcase_30 AC 636 ms
67,416 KB
testcase_31 AC 653 ms
63,552 KB
testcase_32 AC 629 ms
63,320 KB
testcase_33 AC 637 ms
65,412 KB
testcase_34 AC 80 ms
22,784 KB
testcase_35 AC 80 ms
23,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Schema;

public static class Ex
{
    public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); }
    public static void yesno(this bool b) => Console.WriteLine(b ? "yes" : "no");
    public static void YesNo(this bool b) => Console.WriteLine(b ? "Yes" : "No");
    public static void YESNO(this bool b) => Console.WriteLine(b ? "YES" : "NO");
    //[MethodImpl(MethodImplOptions.AggressiveInlining)]
    //public static bool Chmax<T>(ref this T a, T b) where T : struct, IComparable<T>
    //{
    //    if (b.CompareTo(a) > 0) { a = b; return true; }
    //    else return false;
    //}
    //[MethodImpl(MethodImplOptions.AggressiveInlining)]
    //public static bool Chmin<T>(ref this T a, T b) where T : struct, IComparable<T>
    //{
    //    if (b.CompareTo(a) < 0) { a = b; return true; }
    //    else return false;
    //}

    public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); }

    public static int PopCount(this uint bits)
    {
        bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
        bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
        bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
        bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
        return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));
    }
}



partial class Program
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string GetStr() { return Console.ReadLine().Trim(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char GetChar() { return Console.ReadLine().Trim()[0]; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string[][] GetStrArray(int N)
    {
        var res = new string[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ');
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int[][] GetIntArray(int N)
    {
        var res = new int[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    long[][] GetLongArray(int N)
    {
        var res = new long[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double[][] GetDoubleArray(int N)
    {
        var res = new double[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char[][] GetGrid(int H)
    {
        var res = new char[H][];
        for (int i = 0; i < H; i++) res[i] = Console.ReadLine().Trim().ToCharArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[] CreateArray<T>(int N, T value)
    {
        var res = new T[N];
        for (int i = 0; i < N; i++) res[i] = value;
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[][] CreateArray<T>(int H, int W, T value)
    {
        var res = new T[H][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W];
            for (int j = 0; j < W; j++) res[i][j] = value;
        }
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[][][] CreateArray<T>(int H, int W, int R, T value)
    {
        var res = new T[H][][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W][];
            for (int j = 0; j < W; j++)
            {
                res[i][j] = new T[R];
                for (int k = 0; k < R; k++) res[i][j][k] = value;
            }
        }
        return res;
    }

    Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)
    {
        var dic = new Dictionary<int, List<int>>();
        foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); }
        for (int i = 0; i < M; i++)
        {
            var input = GetIntArray();
            var a = isNode_0indexed ? input[0] : input[0] - 1;
            var b = isNode_0indexed ? input[1] : input[1] - 1;
            dic[a].Add(b);
            if (isDirected == false) dic[b].Add(a);
        }
        return dic;
    }
    //Dictionary<int, List<(int node, long cost)>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)
    //{
    //    var dic = new Dictionary<int, List<(int, long)>>();
    //    foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<(int, long)>()); }
    //    for (int i = 0; i < M; i++)
    //    {
    //        var input = GetIntArray();
    //        var a = isNode_0indexed ? input[0] : input[0] - 1;
    //        var b = isNode_0indexed ? input[1] : input[1] - 1;
    //        var c = input[2];
    //        dic[a].Add((b, c));
    //        if (isDirected == false) dic[b].Add((a, c));
    //    }
    //    return dic;
    //}

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T>(out T a) => a = cv<T>(GetStr());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U>(out T a, out U b)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V>(out T a, out U b, out V c)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Output<T>(T t) => Console.WriteLine(t);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Output<T>(IList<T> ls) => Console.WriteLine(string.Join(" ", ls));
    void Debug<T>(IList<IList<T>> ls)
    {
        foreach (var l in ls)
            foreach (var s in l)
                Console.WriteLine(s);
    }


    void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }

    int[] dx = new int[] { 1, 0, -1, 0, 1, -1, -1, 1 };
    int[] dy = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };
    long mod = 1000000007;
}






partial class Program
{
    static void Main()
    {
        Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
        Console.Read();
    }

    public void Solve()
    {
        int N = GetInt();
        var pos = GetLongArray(N);
        List<Tuple<int, int, long>> ls = new List<Tuple<int, int, long>>();
        for (int i = 0; i < N; i++)
        {
            ls.AddRange(Enumerable.Range(i + 1, N - 1 - i)
                .Select((e, index) => new { value = (pos[e][0] - pos[i][0]) * (pos[e][0] - pos[i][0]) + (pos[e][1] - pos[i][1]) * (pos[e][1] - pos[i][1]), index = index + i + 1 })
                .OrderBy(e => e.value)
                .Select(e => new Tuple<int, int, long>(i, e.index, e.value)));
        }
        ls = ls.OrderBy(e => e.Item3).ToList();
        var set = new HashSet<int>();
        int cnt = 0;
        foreach (var a in ls)
        {
            if (set.Contains(a.Item1) || set.Contains(a.Item2)) continue;
            if (a.Item1 == 0)
            {
                set.Add(a.Item2);
                cnt++;
            }
            else
            {
                set.Add(a.Item1);
                set.Add(a.Item2);
            }
            if (set.Count == N - 1) break;
        }

        Output(cnt);
    }
}
0