結果
問題 | No.2165 Let's Play Nim! |
ユーザー | kakel-san |
提出日時 | 2023-02-04 18:10:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,804 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 115,068 KB |
実行使用メモリ | 45,220 KB |
平均クエリ数 | 2.03 |
最終ジャッジ日時 | 2024-07-03 15:00:37 |
合計ジャッジ時間 | 6,818 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
43,928 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | WA | - |
testcase_11 | RE | - |
testcase_12 | WA | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | RE | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 50 ms
41,760 KB |
testcase_31 | AC | 49 ms
42,032 KB |
testcase_32 | WA | - |
evil_2_big_1.txt | RE | - |
evil_2_big_2.txt | WA | - |
evil_2_big_3.txt | WA | - |
evil_big_1.txt | WA | - |
evil_big_2.txt | RE | - |
evil_big_3.txt | RE | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var xor = a.Aggregate((l, r) => l ^ r); var list = new Pair[n]; for (var i = 0; i < n; ++i) list[i] = new Pair(i + 1, a[i]); var q = new PriorityQueue<Pair>(n, true); for (var i = 0; i < n; ++i) q.Enqueue(list[i]); var late = xor == 0; WriteLine(late ? "0" : "1"); while (true) { if (!late) { while (q.List[0].Edited) { var mv = q.Dequeue(); mv.Edited = false; q.Enqueue(mv); } { var mv = q.Dequeue(); WriteLine($"{mv.Pos} {xor}"); mv.Val -= xor; q.Enqueue(mv); xor = 0; } var ret = NN; if (ret < 0) return; } { var c = NList; var i = c[0] - 1; var k = c[1]; xor = xor ^ list[i].Val ^ (list[i].Val - k); list[i].Val -= k; list[i].Edited = true; late = false; var ret = NN; if (ret < 0) return; } } } class Pair : IComparable<Pair> { public int Pos; public int Val; public bool Edited; public Pair(int pos, int val) { Pos = pos; Val = val; } public int CompareTo(Pair b) { return Val.CompareTo(b.Val); } } class PriorityQueue<T> where T : IComparable<T> { public T[] List; public int Count; bool IsTopMax; public PriorityQueue(int count, bool isTopMax) { IsTopMax = isTopMax; List = new T[Math.Max(128, count)]; } public void Enqueue(T value) { if (Count == List.Length) { var newlist = new T[List.Length * 2]; for (var i = 0; i < List.Length; ++i) newlist[i] = List[i]; List = newlist; } var pos = Count; List[pos] = value; ++Count; while (pos > 0) { var parent = (pos - 1) / 2; if (Calc(List[parent], List[pos], true)) break; Swap(parent, pos); pos = parent; } } public T Dequeue() { --Count; Swap(0, Count); var pos = 0; while (true) { var child = pos * 2 + 1; if (child >= Count) break; if (child + 1 < Count && Calc(List[child + 1], List[child], false)) ++child; if (Calc(List[pos], List[child], true)) break; Swap(pos, child); pos = child; } return List[Count]; } bool Calc(T a, T b, bool equalVal) { var ret = a.CompareTo(b); if (ret == 0 && equalVal) return true; return IsTopMax ? ret > 0 : ret < 0; } void Swap(int a, int b) { var tmp = List[a]; List[a] = List[b]; List[b] = tmp; } } }