結果

問題 No.1477 Lamps on Graph
ユーザー g4np0n_kyoprog4np0n_kyopro
提出日時 2021-04-16 20:23:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 16,763 bytes
コンパイル時間 2,785 ms
コンパイル使用メモリ 115,968 KB
実行使用メモリ 47,104 KB
最終ジャッジ日時 2024-07-02 22:31:53
合計ジャッジ時間 11,049 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
19,584 KB
testcase_01 AC 35 ms
19,456 KB
testcase_02 AC 34 ms
19,712 KB
testcase_03 AC 37 ms
19,456 KB
testcase_04 AC 35 ms
19,584 KB
testcase_05 AC 34 ms
19,712 KB
testcase_06 AC 35 ms
19,712 KB
testcase_07 AC 36 ms
19,584 KB
testcase_08 AC 35 ms
19,456 KB
testcase_09 AC 35 ms
19,584 KB
testcase_10 AC 34 ms
19,840 KB
testcase_11 AC 34 ms
19,584 KB
testcase_12 AC 192 ms
38,016 KB
testcase_13 AC 177 ms
38,784 KB
testcase_14 AC 233 ms
40,064 KB
testcase_15 AC 123 ms
30,080 KB
testcase_16 AC 98 ms
33,024 KB
testcase_17 AC 95 ms
32,000 KB
testcase_18 AC 198 ms
45,180 KB
testcase_19 AC 178 ms
39,924 KB
testcase_20 AC 92 ms
27,776 KB
testcase_21 AC 189 ms
42,488 KB
testcase_22 AC 84 ms
25,216 KB
testcase_23 AC 151 ms
31,104 KB
testcase_24 AC 262 ms
41,596 KB
testcase_25 AC 116 ms
29,312 KB
testcase_26 AC 243 ms
43,132 KB
testcase_27 AC 135 ms
31,616 KB
testcase_28 AC 155 ms
36,992 KB
testcase_29 AC 142 ms
33,536 KB
testcase_30 AC 121 ms
38,400 KB
testcase_31 AC 100 ms
34,432 KB
testcase_32 AC 309 ms
46,720 KB
testcase_33 AC 290 ms
46,580 KB
testcase_34 AC 286 ms
46,720 KB
testcase_35 AC 319 ms
46,972 KB
testcase_36 AC 312 ms
46,836 KB
testcase_37 AC 289 ms
47,104 KB
testcase_38 AC 305 ms
46,836 KB
testcase_39 AC 317 ms
47,092 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.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Numerics;
using System.Threading;

partial class Program
{
    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;
    long mod = 998244353;

    public void Solve()
    {
        var (N, M) = io.GetMulti<int, int>();
        var A = io.GetIntArray();
        var zyun = A.Select((value, idx) => new { value = value, idx = idx }).OrderBy(e => e.value).Select(e => e.idx).ToArray();
        var G = io.GetUnweightedAdjanceyList(N, M, false, false);
        var K = io.GetInt();
        var right = new bool[N];
        foreach (var b in io.GetIntArray()) right[b - 1] = true;
        var ans = new List<int>();
        for(int i = 0; i < N; i++)
        {
            var idx = zyun[i];
            if (right[idx]==false) continue;
            right[idx] = false;
            ans.Add(idx);
            foreach(var next in G[idx])
            {
                if (A[idx] >= A[next]) continue;
                right[next] = !right[next];
            }
        }
        io.Print(ans.Count);
        foreach (var a in ans) io.Print(a + 1);
    }

    IO io = new IO();
    static void Main()
    {
        Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var program = new Program();
        //var t = new Thread(program.Solve, 134217728);
        //t.Start();
        //t.Join();
        program.Solve();
        Console.Out.Flush();
        Console.Read();
    }
}

//------------------------------------------------------------------------------------------------------------------

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");
    public static void Yes() => Console.WriteLine("Yes");
    public static void YES() => Console.WriteLine("YES");
    public static void No() => Console.WriteLine("No");
    public static void NO() => Console.WriteLine("NO");
    public static void M1() => Console.WriteLine("-1");
    ////[MethodImpl(MethodImplOptions.AggressiveInlining)]
    ////public static bool Chmax(ref this int a, int b)
    ////{
    ////    if (a < b) { a = b; return true; }
    ////    else return false;
    ////}
    ////[MethodImpl(MethodImplOptions.AggressiveInlining)]
    ////public static bool Chmin(ref this int a, int b)
    ////{
    ////    if (a > b) { a = b; return true; }
    ////    else return false;
    ////}
    ////[MethodImpl(MethodImplOptions.AggressiveInlining)]
    ////public static bool Chmax(ref this long a, long b)
    ////{
    ////    if (a < b) { a = b; return true; }
    ////    else return false;
    ////}
    ////[MethodImpl(MethodImplOptions.AggressiveInlining)]
    ////public static bool Chmin<T>(ref this long a, long b)
    ////{
    ////    if (a > b) { a = b; return true; }
    ////    else return false;
    ////}
    ////[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;
    ////}

    /// <summary>
    /// constraintを満たす最小のインデックスを返します。
    /// </summary>
    /// <param name="constraint">T key が満たすべき制約</param>
    /// <returns>制約を満たす最小のインデックス(0-indexed)</returns>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static int LowerBound<T>(this IList<T> ls, Func<T, bool> constraint)
    {
        var ng = -1;
        var ok = ls.Count;
        while (ok - ng > 1)
        {
            var mid = (ok + ng) / 2;
            if (constraint(ls[mid])) ok = mid;
            else ng = mid;
        }
        return ok;

    }

    /// <summary>
    /// 配列の累積演算結果の配列を返します。
    /// </summary>
    /// <param name="fromLeft">左から順に計算するか?</param>
    /// <param name="gen">単位元</param>
    /// <param name="func">演算</param>
    /// <returns>要素数N+1の累積演算テーブル</returns>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] GetCum<T>(this IList<T> ls, bool fromLeft, T gen, Func<T, T, T> func)
    {
        var res = new T[ls.Count + 1];
        res.AsSpan().Fill(gen);
        if (fromLeft)
        {
            for (int i = 0; i < ls.Count; i++) res[i + 1] = func(res[i], ls[i]);
        }
        else
        {
            for (int i = ls.Count; i > 0; i--) res[i - 1] = func(res[i], ls[i - 1]);
        }
        return res;
    }

    /// <summary>
    /// 文字列のIListを昇順にソートして返します。
    /// </summary>
    /// <param name="ls"></param>
    /// <returns>昇順の文字列配列</returns>
    public static string[] StringListFastSort(this IList<string> ls)
    {
        var res = ls.ToArray();
        Array.Sort(res, StringComparer.OrdinalIgnoreCase);
        return res;
    }

    /// <summary>
    /// 立っているビットの数を返します。
    /// </summary>
    public static int PopCount(this uint bits)
    {
        bits = bits - ((bits >> 1) & 0x55555555);
        bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333);
        return (int)(((bits + (bits >> 4) & 0xF0F0F0F) * 0x1010101) >> 24);
    }

    /// <summary>
    /// elementで満たされた一次元配列を返します。
    /// </summary>
    public static T[] Repeat<T>(this T element, int N)
    {
        var res = new T[N];
        res.AsSpan().Fill(element);
        return res;
    }

    /// <summary>
    /// elementで満たされた二次元配列を返します。
    /// </summary>
    public static T[][] Repeat<T>(this T element, int H, int W)
    {
        var res = new T[H][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W];
            res[i].AsSpan().Fill(element);
        }
        return res;
    }

    /// <summary>
    /// elementで満たされた三次元配列を返します。
    /// </summary>
    public static T[][][] Repeat<T>(this T element, int H, int W, int R)
    {
        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];
                res[i][j].AsSpan().Fill(element);
            }
        }
        return res;
    }

}

class IO
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string GetStr() => Console.ReadLine().Trim();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public char GetChar() => Console.ReadLine().Trim()[0];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetInt() => int.Parse(Console.ReadLine().Trim());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public long GetLong() => long.Parse(Console.ReadLine().Trim());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public double GetDouble() => double.Parse(Console.ReadLine().Trim());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public decimal GetDecimal() => decimal.Parse(Console.ReadLine().Trim());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string[] GetStrArray() => Console.ReadLine().Trim().Split(' ');
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public 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)]
    public int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public 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() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public 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)]
    public decimal[] GetDecimalArray() => Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public decimal[][] GetDecimalArray(int N)
    {
        var res = new decimal[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public char[] GetCharArray() => Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public double[] GetDoubleArray() => Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public 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)]
    public char[][] GetGrid(int H)
    {
        var res = new char[H][];
        for (int i = 0; i < H; i++) res[i] = Console.ReadLine().Trim().ToCharArray();
        return res;
    }

    public List<int>[] GetUnweightedAdjanceyList(int V, int E, bool isDirected, bool isNode_0indexed)
    {
        var ls = new List<int>[V];
        for (int i = 0; i < V; i++) ls[i] = new List<int>();
        for (int i = 0; i < E; i++)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (isNode_0indexed == false) { input[0]--; input[1]--; }
            ls[input[0]].Add(input[1]);
            if (isDirected == false) ls[input[1]].Add(input[0]);
        }
        return ls;
    }

    public Dictionary<int, List<int>> GetUnweightedAdjacencyDict(int V, int E, bool isDirected, bool isNode_0indexed)
    {
        var dic = new Dictionary<int, List<int>>();
        foreach (var e in Enumerable.Range(0, V)) { dic.Add(e, new List<int>()); }
        for (int i = 0; i < E; 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;
    }

    public List<(int to, long dist)>[] GetWeightedAdjacencyList(int V, int E, bool isDirected, bool isNode_0indexed)
    {
        var ls = new List<(int to, long dist)>[V];
        for (int i = 0; i < V; i++) ls[i] = new List<(int to, long dist)>();
        for (int i = 0; i < E; i++)
        {
            var hoge = Console.ReadLine().Split(' ');
            var a = int.Parse(hoge[0]);
            var b = int.Parse(hoge[1]);
            var c = long.Parse(hoge[2]);
            if (isNode_0indexed == false) { a--; b--; }
            ls[a].Add((b, c));
            if (isDirected == false) ls[b].Add((a, c));
        }
        return ls;
    }

    //public Dictionary<int, List<(int node, long cost)>> GetWeightedAdjacencyDict(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, decimal>() ? ct<T, decimal>(decimal.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)]
    public (T, U) GetMulti<T, U>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V) GetMulti<T, U, V>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W) GetMulti<T, U, V, W>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W, X) GetMulti<T, U, V, W, X>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]), cv<X>(ar[4]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W, X, Y) GetMulti<T, U, V, W, X, Y>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]), cv<X>(ar[4]), cv<Y>(ar[5]));
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print() => Console.WriteLine();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print<T>(T t) => Console.WriteLine(t);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print<T>(string separator, IList<T> ls) => Console.WriteLine(string.Join(separator, ls));
    public void Debug<T>(IList<T> ls)
    {
        Console.Error.WriteLine();
        Console.Error.WriteLine("[" + string.Join(",", ls) + "]");
    }
    public void Debug<T>(IList<IList<T>> ls)
    {
        Console.Error.WriteLine();
        foreach (var l in ls)
        {
            Console.Error.WriteLine("[" + string.Join(",", l) + "]");
        }
        Console.Error.WriteLine();
    }
}
0