結果
| 問題 |
No.429 CupShuffle
|
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2017-10-09 20:28:05 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 270 ms / 2,000 ms |
| コード長 | 10,640 bytes |
| コンパイル時間 | 1,181 ms |
| コンパイル使用メモリ | 115,840 KB |
| 実行使用メモリ | 24,320 KB |
| 最終ジャッジ日時 | 2024-11-17 07:02:35 |
| 合計ジャッジ時間 | 3,907 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}
}
くれちー