結果
問題 | No.1355 AND OR GAME |
ユーザー |
|
提出日時 | 2021-01-24 13:06:17 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,171 bytes |
コンパイル時間 | 2,898 ms |
コンパイル使用メモリ | 110,080 KB |
実行使用メモリ | 161,444 KB |
最終ジャッジ日時 | 2025-01-02 16:50:12 |
合計ジャッジ時間 | 31,978 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 93 TLE * 2 |
コンパイルメッセージ
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; class F { static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); static (long, long, long) Read3L() { var a = ReadL(); return (a[0], a[1], a[2]); } static void Main() => Console.WriteLine(Solve()); static object Solve() { var (n, x, y) = ((int, long, long))Read3L(); var a = ReadL(); var r60 = Enumerable.Range(0, 60).ToArray(); bool[] ToBool(long v) => Array.ConvertAll(r60, i => (v & (1L << i)) != 0); bool?[] ToBoolN(long v) => Array.ConvertAll(r60, i => (bool?)((v & (1L << i)) != 0)); bool Match(bool x, bool? y) => y == null || x == y; bool Matches(bool[] x, bool?[] y) => Array.TrueForAll(r60, i => Match(x[i], y[i])); var p = new Stack<int>(); var xf = ToBool(x); bool Dfs(int i, bool?[] yf) { if (i < 0) { return Matches(xf, yf); } else { var af = ToBool(a[i]); if (Matches(af, yf)) { p.Push(3); while (p.Count < n) p.Push(1); return true; } { var ok = true; var t = new bool?[60]; for (int f = 0; f < 60; f++) { var mt = Match(af[f] & true, yf[f]); var mf = Match(af[f] & false, yf[f]); if (mt && mf) { } else if (mt) t[f] = true; else if (mf) t[f] = false; else { ok = false; break; } } if (ok) { p.Push(1); if (Dfs(i - 1, t)) return true; p.Pop(); } } { var ok = true; var t = new bool?[60]; for (int f = 0; f < 60; f++) { var mt = Match(af[f] | true, yf[f]); var mf = Match(af[f] | false, yf[f]); if (mt && mf) { } else if (mt) t[f] = true; else if (mf) t[f] = false; else { ok = false; break; } } if (ok) { p.Push(2); if (Dfs(i - 1, t)) return true; p.Pop(); } } return false; } } if (!Dfs(n - 1, ToBoolN(y))) return -1; { var pa = p.ToArray(); for (int i = 0; i < n; i++) if (pa[i] == 1) x &= a[i]; else if (pa[i] == 2) x |= a[i]; else x = a[i]; if (x != y) throw new InvalidOperationException(); } return string.Join(" ", p); } }