結果
問題 | No.726 Tree Game |
ユーザー | sekiya9311 |
提出日時 | 2018-08-24 22:02:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 10,731 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 113,920 KB |
実行使用メモリ | 20,224 KB |
最終ジャッジ日時 | 2024-06-23 07:25:38 |
合計ジャッジ時間 | 2,352 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
19,456 KB |
testcase_01 | AC | 28 ms
19,072 KB |
testcase_02 | AC | 31 ms
19,584 KB |
testcase_03 | WA | - |
testcase_04 | AC | 26 ms
19,200 KB |
testcase_05 | AC | 29 ms
19,456 KB |
testcase_06 | AC | 25 ms
19,072 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 35 ms
19,712 KB |
testcase_11 | AC | 29 ms
19,456 KB |
testcase_12 | AC | 29 ms
19,328 KB |
testcase_13 | WA | - |
testcase_14 | AC | 26 ms
19,200 KB |
testcase_15 | AC | 31 ms
19,328 KB |
testcase_16 | WA | - |
testcase_17 | AC | 29 ms
19,584 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 30 ms
19,712 KB |
testcase_22 | AC | 32 ms
20,224 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
コンパイルメッセージ
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.Linq; using System.Text; namespace ProgrammingContest { class Writer : IDisposable { private System.IO.TextWriter Out { get; } private StringBuilder Sb { get; } private bool IsReactive { get; } public Writer(string path) : this(new System.IO.StreamWriter(path)) { } public Writer(bool isReactive) : this(null, isReactive) { } public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.Out = (writer ?? Console.Out); this.IsReactive = isReactive; if (!this.IsReactive) { this.Sb = new StringBuilder(); } } public void Dispose() { if (!this.IsReactive) { this.Out.Write(Sb.ToString()); } if (!this.Out.Equals(Console.Out)) { this.Out.Dispose(); } } public void Write(object val) { if (this.IsReactive) { this.Out.Write(val.ToString()); this.Out.Flush(); } else { this.Sb.Append(val.ToString()); } } public void WriteFormat(string format, params object[] vals) { if (this.IsReactive) { this.Out.Write(format, vals); this.Out.Flush(); } else { this.Sb.AppendFormat(format, vals); } } public void WriteLine(object val = null) { this.WriteFormat((val ?? string.Empty).ToString() + Environment.NewLine); } public void WriteLine(int val) { this.WriteLine(val.ToString()); } public void WriteLine(long val) { this.WriteLine(val.ToString()); } public void WriteLine(string val) { this.WriteLine((object)val); } public void WriteLine(string format, params object[] vals) { this.WriteFormat(format + Environment.NewLine, vals); } } class Scanner : IDisposable { private Queue<string> Buffer { get; } private char[] Sep { get; } private System.IO.TextReader Reader { get; } public Scanner(string path, char[] sep = null) : this(new System.IO.StreamReader(path), sep) { } public Scanner(System.IO.TextReader reader = null, char[] sep = null) { this.Buffer = new Queue<string>(); this.Sep = (sep ?? new char[] { ' ' }); this.Reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.Buffer.Count == 0 && this.Reader.Peek() != -1) { string str = string.Empty; for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str); str = this.Reader.ReadLine()) ; var strs = str.Split(this.Sep).Where(el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el))); foreach (var el in strs) { this.Buffer.Enqueue(el); } } } public void Dispose() { if (!this.Reader.Equals(Console.In)) { this.Reader.Dispose(); } } public string Next() { this.CheckBuffer(); return this.Buffer.Dequeue(); } public string[] GetStringArray(int N) { return Enumerable.Range(0, N) .Select(e => this.Next()) .ToArray(); } public int NextInt() { return int.Parse(this.Next()); } public int[] GetIntArray(int N) { return Enumerable.Range(0, N) .Select(e => this.NextInt()) .ToArray(); } public double NextDouble() { return double.Parse(this.Next()); } public double[] GetdoubleArray(int N) { return Enumerable.Range(0, N) .Select(e => this.NextDouble()) .ToArray(); } public long NextLong() { return long.Parse(this.Next()); } public long[] GetLongArray(int N) { return Enumerable.Range(0, N) .Select(e => this.NextLong()) .ToArray(); } public bool IsEnd { get { this.CheckBuffer(); return this.Buffer.Count == 0; } } } class MainClass : IDisposable { private Scanner Sc { get; } private Writer Wr { get; } static string BackPath { get; } = ".."; private char DirSep { get; } = System.IO.Path.DirectorySeparatorChar; private string InFilePath { get; } = string.Empty; private string OutFilePath { get; } = string.Empty; public MainClass() { this.InFilePath = MainClass.BackPath + this.DirSep + MainClass.BackPath + this.DirSep + "in.txt"; this.OutFilePath = MainClass.BackPath + this.DirSep + MainClass.BackPath + this.DirSep + "out.txt"; this.Wr = new Writer(this.IsReactive); //this.wr = new Writer(this.OutFilePath); #if DEBUG if (!this.IsReactive) { this.Sc = new Scanner(this.InFilePath); } else { this.Sc = new Scanner(); } #else this.Sc = new Scanner(); #endif } static void Main(string[] args) { using (var mainClass = new MainClass()) { mainClass.Solve(); } } public void Dispose() { this.Sc?.Dispose(); this.Wr?.Dispose(); #if DEBUG Console.WriteLine("press any key to continue..."); Console.ReadKey(); #endif } bool IsPrime(long v) { if (v < 2) { return false; } for (long i = 2; i * i <= v; i++) { if (v % i == 0) { return false; } } return true; } Dictionary<Pair<long, long>, bool> dicPrimePoint = new Dictionary<Pair<long, long>, bool>(); Dictionary<long, bool> dicPrime = new Dictionary<long, bool>(); bool Dfs(Pair<long, long> p, int cnt) { if (!dicPrimePoint.ContainsKey(p)) { if (!dicPrime.ContainsKey(p.First)) { dicPrime.Add(p.First, IsPrime(p.First)); } if (!dicPrime.ContainsKey(p.Second)) { dicPrime.Add(p.Second, IsPrime(p.Second)); } if (dicPrime[p.First] || dicPrime[p.Second]) { dicPrimePoint.Add(p, cnt % 2 == 1); } else { var p1 = p.Clone(); var p2 = p.Clone(); p1.First++; p2.Second++; bool foo1 = Dfs(p1, cnt + 1); bool foo2 = Dfs(p2, cnt + 1); if (cnt % 2 == 0) { if (foo1 || foo2) { dicPrimePoint.Add(p, true); } else { dicPrimePoint.Add(p, false); } } else { if (!foo1 && !foo2) { dicPrimePoint.Add(p, false); } else { dicPrimePoint.Add(p, true); } } } } if (cnt % 2 == 0) { return dicPrimePoint[p]; } else { return !dicPrimePoint[p]; } } void Solve() { long Y = Sc.NextInt(); long X = Sc.NextInt(); if (IsPrime(X) || IsPrime(Y)) { Wr.WriteLine("First"); return; } Wr.WriteLine(Dfs(new Pair<long, long>(X, Y), 0) ? "First" : "Second"); } private bool IsReactive { get; } = false; // TODO: reactive check !! } internal class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 First { get; set; } public T2 Second { get; set; } public Pair() { } public Pair(T1 f, T2 s) { this.First = f; this.Second = s; } public int CompareTo(Pair<T1, T2> other) { int ret = 0; if (First is IComparable<T1>) { ret = (First as IComparable<T1>).CompareTo(other.First); } if (ret == 0 && Second is IComparable<T2>) { ret = (Second as IComparable<T2>).CompareTo(other.Second); } return ret; } public override bool Equals(object obj) { if (obj is Pair<T1, T2>) { var other = obj as Pair<T1, T2>; return this.First.Equals(other.First) && this.Second.Equals(other.Second); } else { return false; } } public override int GetHashCode() { return this.First.GetHashCode() ^ this.Second.GetHashCode(); } public Pair<T1, T2> Clone() { var p = new Pair<T1, T2>(this.First, this.Second); return p; } } }