結果

問題 No.1355 AND OR GAME
ユーザー さかぽんさかぽん
提出日時 2021-01-24 12:20:41
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,095 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 106,972 KB
実行使用メモリ 157,540 KB
最終ジャッジ日時 2023-08-30 20:01:09
合計ジャッジ時間 40,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,700 KB
testcase_01 AC 63 ms
21,728 KB
testcase_02 AC 70 ms
23,956 KB
testcase_03 AC 70 ms
21,904 KB
testcase_04 AC 70 ms
19,996 KB
testcase_05 AC 64 ms
23,892 KB
testcase_06 AC 70 ms
22,056 KB
testcase_07 AC 70 ms
24,032 KB
testcase_08 AC 71 ms
21,928 KB
testcase_09 AC 70 ms
21,804 KB
testcase_10 AC 62 ms
21,872 KB
testcase_11 AC 62 ms
21,848 KB
testcase_12 AC 63 ms
23,912 KB
testcase_13 AC 61 ms
21,836 KB
testcase_14 AC 61 ms
23,756 KB
testcase_15 AC 61 ms
21,732 KB
testcase_16 RE -
testcase_17 AC 62 ms
21,836 KB
testcase_18 RE -
testcase_19 AC 61 ms
21,896 KB
testcase_20 AC 63 ms
21,808 KB
testcase_21 AC 63 ms
21,836 KB
testcase_22 AC 63 ms
23,776 KB
testcase_23 AC 62 ms
21,868 KB
testcase_24 AC 62 ms
21,820 KB
testcase_25 AC 62 ms
19,692 KB
testcase_26 AC 63 ms
21,752 KB
testcase_27 AC 62 ms
21,656 KB
testcase_28 AC 64 ms
21,924 KB
testcase_29 AC 65 ms
21,864 KB
testcase_30 AC 67 ms
23,792 KB
testcase_31 AC 63 ms
23,844 KB
testcase_32 AC 63 ms
21,748 KB
testcase_33 AC 64 ms
21,860 KB
testcase_34 RE -
testcase_35 AC 235 ms
54,224 KB
testcase_36 WA -
testcase_37 AC 61 ms
21,728 KB
testcase_38 RE -
testcase_39 AC 122 ms
39,940 KB
testcase_40 AC 154 ms
43,416 KB
testcase_41 AC 235 ms
52,072 KB
testcase_42 TLE -
testcase_43 AC 160 ms
46,052 KB
testcase_44 RE -
testcase_45 AC 235 ms
56,072 KB
testcase_46 AC 132 ms
39,248 KB
testcase_47 RE -
testcase_48 AC 190 ms
47,652 KB
testcase_49 WA -
testcase_50 AC 62 ms
21,680 KB
testcase_51 AC 154 ms
45,768 KB
testcase_52 RE -
testcase_53 AC 176 ms
43,376 KB
testcase_54 AC 240 ms
56,252 KB
testcase_55 AC 205 ms
53,836 KB
testcase_56 AC 206 ms
53,768 KB
testcase_57 AC 191 ms
49,240 KB
testcase_58 AC 100 ms
28,388 KB
testcase_59 AC 63 ms
21,828 KB
testcase_60 AC 182 ms
46,216 KB
testcase_61 AC 62 ms
21,728 KB
testcase_62 AC 133 ms
37,508 KB
testcase_63 AC 240 ms
56,140 KB
testcase_64 AC 205 ms
51,952 KB
testcase_65 RE -
testcase_66 AC 116 ms
38,948 KB
testcase_67 AC 125 ms
39,312 KB
testcase_68 RE -
testcase_69 AC 62 ms
21,824 KB
testcase_70 AC 132 ms
39,588 KB
testcase_71 RE -
testcase_72 AC 236 ms
54,064 KB
testcase_73 AC 238 ms
56,084 KB
testcase_74 RE -
testcase_75 RE -
testcase_76 AC 237 ms
56,008 KB
testcase_77 RE -
testcase_78 AC 61 ms
21,716 KB
testcase_79 AC 62 ms
21,788 KB
testcase_80 AC 237 ms
54,024 KB
testcase_81 RE -
testcase_82 RE -
testcase_83 AC 206 ms
53,812 KB
testcase_84 AC 409 ms
75,556 KB
testcase_85 AC 1,267 ms
123,056 KB
testcase_86 AC 756 ms
89,760 KB
testcase_87 AC 587 ms
82,804 KB
testcase_88 AC 97 ms
29,380 KB
testcase_89 AC 79 ms
25,180 KB
testcase_90 AC 1,927 ms
148,352 KB
testcase_91 AC 154 ms
46,592 KB
testcase_92 AC 111 ms
30,932 KB
testcase_93 AC 1,551 ms
136,600 KB
testcase_94 AC 747 ms
93,396 KB
testcase_95 AC 528 ms
75,436 KB
testcase_96 AC 385 ms
66,916 KB
testcase_97 AC 108 ms
32,748 KB
testcase_98 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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 & (1 << i)) != 0);
		bool?[] ToBoolN(long v) => Array.ConvertAll(r60, i => (bool?)((v & (1 << i)) != 0));
		bool Matches(bool[] x, bool?[] y) => Array.TrueForAll(r60, i => (x[i] ^ y[i]) != true);

		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++)
					{
						if (yf[f] == null || (af[f] & null) == yf[f]) { }
						else if ((af[f] & true) == yf[f]) t[f] = true;
						else if ((af[f] & false) == yf[f]) 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++)
					{
						if (yf[f] == null || (af[f] | null) == yf[f]) { }
						else if ((af[f] | true) == yf[f]) t[f] = true;
						else if ((af[f] | false) == yf[f]) 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);
	}
}
0