結果

問題 No.429 CupShuffle
ユーザー くれちーくれちー
提出日時 2017-10-09 20:30:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 10,639 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 116,096 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2024-11-17 07:02:39
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
19,328 KB
testcase_01 AC 27 ms
19,072 KB
testcase_02 AC 27 ms
19,072 KB
testcase_03 AC 26 ms
19,200 KB
testcase_04 AC 27 ms
19,456 KB
testcase_05 AC 27 ms
18,944 KB
testcase_06 AC 29 ms
19,456 KB
testcase_07 AC 28 ms
19,200 KB
testcase_08 AC 27 ms
19,072 KB
testcase_09 AC 29 ms
19,200 KB
testcase_10 AC 51 ms
23,024 KB
testcase_11 AC 265 ms
24,192 KB
testcase_12 AC 253 ms
24,192 KB
testcase_13 AC 267 ms
24,064 KB
testcase_14 AC 268 ms
24,192 KB
testcase_15 AC 28 ms
19,072 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.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using CSharp7.Library;
using static System.Math;
using static System.Linq.Enumerable;
using static CSharp7.Library.Extentions;

namespace CSharp7
{
    public static class Program
    {
        public static void Solve(IO io)
        {
            var (n, k, x) = io.Read<int, int, int>();
            var (a, b) = io.ReadMany<int, int>(x - 1);
            io.ReadLine();
            var (ra, rb) = io.ReadMany<int, int>(k - x);
            var rc = io.ReadMany<int>(n);
            var c = Range(1, n).ToArray();

            for (var i = 0; i < a.Length; i++)
                Swap(ref c[a[i] - 1], ref c[b[i] - 1]);
            for (var i = ra.Length - 1; i >= 0; i--)
                Swap(ref rc[ra[i] - 1], ref rc[rb[i] - 1]);

            for (var i = 0; i < c.Length; i++)
                if (c[i] != rc[i]) io.Write(i + 1);
        }

        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
            sw.AutoFlush = true;
#else
            sw.AutoFlush = false;
#endif
            Console.SetOut(sw);
            Solve(new IO(Console.In, Console.Out));
            Console.Out.Flush();
        }
    }
}

namespace CSharp7.Library
{
    public delegate T Parser<out T>(string str);

    public delegate string Serializer<in T>(T value);

    public class IO
    {
        private static readonly Dictionary<Type, Delegate> _parsers = new Dictionary<Type, Delegate>
        {
            { typeof(string), (Parser<string>)(s => s) },
            { typeof(char), (Parser<char>)char.Parse },
            { typeof(int), (Parser<int>)int.Parse },
            { typeof(long), (Parser<long>)long.Parse },
            { typeof(double), (Parser<double>)double.Parse },
            { typeof(decimal), (Parser<decimal>)decimal.Parse },
            { typeof(BigInteger), (Parser<BigInteger>)BigInteger.Parse },
        };

        private static readonly Dictionary<Type, Delegate> _serializers = new Dictionary<Type, Delegate>
        {
            { typeof(string), (Serializer<string>)(s => s) },
            { typeof(char), (Serializer<char>)(c => c.ToString()) },
            { typeof(int), (Serializer<int>)(i => i.ToString()) },
            { typeof(long), (Serializer<long>)(l => l.ToString()) },
            { typeof(double), (Serializer<double>)(d => d.ToString()) },
            { typeof(decimal), (Serializer<decimal>)(d => d.ToString()) },
            { typeof(BigInteger), (Serializer<BigInteger>)(b => b.ToString()) },
        };

        private TextReader _sr;
        private TextWriter _sw;

        public IO(TextReader sr, TextWriter sw)
        {
            _sr = sr;
            _sw = sw;
        }

        public string ReadLine() => _sr.ReadLine();

        public string ReadWord()
        {
            var sb = new StringBuilder();
            var c = _sr.Read();
            while (c != ' ' && c != '\n') { sb.Append((char)c); c = _sr.Read(); }
            return sb.ToString();
        }

        public T Read<T>(Parser<T> p = null)
            => (p ?? GetParser<T>())(ReadWord());

        public (T1, T2) Read<T1, T2>(Parser<T1> p1 = null, Parser<T2> p2 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()));

        public (T1, T2, T3) Read<T1, T2, T3>(
            Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()), Read(p3 ?? GetParser<T3>()));

        public (T1, T2, T3, T4) Read<T1, T2, T3, T4>(
            Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null, Parser<T4> p4 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()),
                Read(p3 ?? GetParser<T3>()), Read(p4 ?? GetParser<T4>()));

        public T[] ReadMany<T>(int count, Parser<T> p = null)
        {
            var a = new T[count];
            for (var i = 0; i < count; i++) a[i] = Read(p);
            return a;
        }

        public (T1[], T2[]) ReadMany<T1, T2>(int count, Parser<T1> p1 = null, Parser<T2> p2 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i]) = Read(p1, p2);
            return (a1, a2);
        }

        public (T1[], T2[], T3[]) ReadMany<T1, T2, T3>(int count,
            Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            var a3 = new T3[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i], a3[i]) = Read(p1, p2, p3);
            return (a1, a2, a3);
        }

        public (T1[], T2[], T3[], T4[]) ReadMany<T1, T2, T3, T4>(int count,
            Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null, Parser<T4> p4 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            var a3 = new T3[count];
            var a4 = new T4[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i], a3[i], a4[i]) = Read(p1, p2, p3, p4);
            return (a1, a2, a3, a4);
        }

        public void Write<T>(T v, Serializer<T> s = null)
        {
            _sw.Write(s?.Invoke(v) ?? GetSerializer<T>()(v));
            _sw.Write(' ');
        }

        public void Write<T1, T2>(T1 v1, T2 v2, Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
        }

        public void Write<T1, T2, T3>(T1 v1, T2 v2, T3 v3,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
            Write(v3, s3);
        }

        public void Write<T1, T2, T3, T4>(T1 v1, T2 v2, T3 v3, T4 v4,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null,
            Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
            Write(v3, s3);
            Write(v4, s4);
        }

        public void WriteLine<T>(T v, Serializer<T> s = null)
        {
            Write(v, s);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2>(T1 v1, T2 v2, Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            Write(v1, v2, s1, s2);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2, T3>(T1 v1, T2 v2, T3 v3,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            Write(v1, v2, v3, s1, s2, s3);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2, T3, T4>(T1 v1, T2 v2, T3 v3, T4 v4,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null,
            Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            Write(v1, v2, v3, v4, s1, s2, s3, s4);
            _sw.WriteLine();
        }

        public void WriteMany<T>(IEnumerable<T> vs, Serializer<T> s = null)
        {
            foreach (var v in vs) Write(v, s);
            _sw.WriteLine();
        }

        public void WriteMany<T1, T2>(IEnumerable<T1> vs1, IEnumerable<T2> vs2,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            foreach (var (v1, v2) in vs1.Zip(vs2, ValueTuple.Create)) Write(v1, v2, s1, s2);
            _sw.WriteLine();
        }

        public void WriteMany<T1, T2, T3>(
            IEnumerable<T1> vs1, IEnumerable<T2> vs2, IEnumerable<T3> vs3,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            foreach (var (v1, v2, v3) in vs1.Zip(vs2, vs3, ValueTuple.Create)) Write(v1, v2, v3, s1, s2, s3);
            _sw.WriteLine();
        }

        public void WriteMany<T1, T2, T3, T4>(
            IEnumerable<T1> vs1, IEnumerable<T2> vs2,
            IEnumerable<T3> vs3, IEnumerable<T4> vs4,
            Serializer<T1> s1 = null, Serializer<T2> s2 = null,
            Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            foreach (var (v1, v2, v3, v4) in vs1.Zip(vs2, vs3, vs4, ValueTuple.Create))
                Write(v1, v2, v3, v4, s1, s2, s3, s4);
            _sw.WriteLine();
        }

        private Parser<T> GetParser<T>() => (Parser<T>)_parsers[typeof(T)];

        private Serializer<T> GetSerializer<T>() => (Serializer<T>)_serializers[typeof(T)];
    }

    public static class Extentions
    {
        public static void Swap<T>(ref T x, ref T y)
        {
            var tmp = x; x = y; y = tmp;
        }

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source) action(item);
        }

        public static void ForEach<T, _>(this IEnumerable<T> source, Func<T, _> func)
        {
            foreach (var item in source) func(item);
        }

        public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
        {
            var i = 0;
            foreach (var item in source) action(item, i++);
        }

        public static void ForEach<T, _>(this IEnumerable<T> source, Func<T, int, _> func)
        {
            var i = 0;
            foreach (var item in source) func(item, i++);
        }

        public static IEnumerable<T> Zip<T1, T2, T3, T>(this IEnumerable<T1> first,
            IEnumerable<T2> second, IEnumerable<T3> thrid,
            Func<T1, T2, T3, T> resultSelector)
        {
            using (var e1 = first.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = thrid.GetEnumerator())
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext())
                    yield return resultSelector(e1.Current, e2.Current, e3.Current);
        }

        public static IEnumerable<T> Zip<T1, T2, T3, T4, T>(this IEnumerable<T1> first,
            IEnumerable<T2> second, IEnumerable<T3> thrid, IEnumerable<T4> fourth,
            Func<T1, T2, T3, T4, T> resultSelector)
        {
            using (var e1 = first.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = thrid.GetEnumerator())
            using (var e4 = fourth.GetEnumerator())
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext())
                    yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current);
        }
    }
}
0