結果

問題 No.1355 AND OR GAME
ユーザー さかぽんさかぽん
提出日時 2021-01-24 13:06:17
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,171 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 109,040 KB
実行使用メモリ 162,760 KB
最終ジャッジ日時 2023-08-30 20:29:40
合計ジャッジ時間 35,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,708 KB
testcase_01 AC 62 ms
21,796 KB
testcase_02 AC 71 ms
21,940 KB
testcase_03 AC 72 ms
22,052 KB
testcase_04 AC 72 ms
23,944 KB
testcase_05 AC 63 ms
21,820 KB
testcase_06 AC 72 ms
24,120 KB
testcase_07 AC 70 ms
21,948 KB
testcase_08 AC 71 ms
22,024 KB
testcase_09 AC 71 ms
19,908 KB
testcase_10 AC 63 ms
21,796 KB
testcase_11 AC 62 ms
21,812 KB
testcase_12 AC 64 ms
23,820 KB
testcase_13 AC 61 ms
21,804 KB
testcase_14 AC 61 ms
23,860 KB
testcase_15 AC 61 ms
21,692 KB
testcase_16 AC 64 ms
21,704 KB
testcase_17 AC 62 ms
21,716 KB
testcase_18 AC 63 ms
21,704 KB
testcase_19 AC 61 ms
21,672 KB
testcase_20 AC 64 ms
23,760 KB
testcase_21 AC 63 ms
23,808 KB
testcase_22 AC 63 ms
21,772 KB
testcase_23 AC 62 ms
21,732 KB
testcase_24 AC 62 ms
21,824 KB
testcase_25 AC 63 ms
21,872 KB
testcase_26 AC 64 ms
21,760 KB
testcase_27 AC 61 ms
21,632 KB
testcase_28 AC 64 ms
23,756 KB
testcase_29 AC 64 ms
21,804 KB
testcase_30 AC 64 ms
21,816 KB
testcase_31 AC 63 ms
21,844 KB
testcase_32 AC 64 ms
23,872 KB
testcase_33 AC 63 ms
21,700 KB
testcase_34 AC 87 ms
23,832 KB
testcase_35 AC 236 ms
56,064 KB
testcase_36 AC 223 ms
54,540 KB
testcase_37 AC 62 ms
21,848 KB
testcase_38 AC 239 ms
56,064 KB
testcase_39 AC 124 ms
37,904 KB
testcase_40 AC 152 ms
43,256 KB
testcase_41 AC 240 ms
54,040 KB
testcase_42 AC 237 ms
56,084 KB
testcase_43 AC 162 ms
48,152 KB
testcase_44 AC 94 ms
26,976 KB
testcase_45 AC 240 ms
54,040 KB
testcase_46 AC 133 ms
39,380 KB
testcase_47 AC 239 ms
54,172 KB
testcase_48 AC 192 ms
49,676 KB
testcase_49 AC 239 ms
54,252 KB
testcase_50 AC 63 ms
19,788 KB
testcase_51 AC 155 ms
45,680 KB
testcase_52 AC 224 ms
54,076 KB
testcase_53 AC 174 ms
47,380 KB
testcase_54 AC 240 ms
56,048 KB
testcase_55 AC 207 ms
53,812 KB
testcase_56 AC 208 ms
51,748 KB
testcase_57 AC 190 ms
49,180 KB
testcase_58 AC 100 ms
30,424 KB
testcase_59 AC 63 ms
23,832 KB
testcase_60 AC 184 ms
46,092 KB
testcase_61 AC 63 ms
21,796 KB
testcase_62 AC 135 ms
41,700 KB
testcase_63 AC 239 ms
53,996 KB
testcase_64 AC 207 ms
51,784 KB
testcase_65 AC 73 ms
22,140 KB
testcase_66 AC 116 ms
36,772 KB
testcase_67 AC 125 ms
39,132 KB
testcase_68 AC 124 ms
39,020 KB
testcase_69 AC 64 ms
21,764 KB
testcase_70 AC 134 ms
39,580 KB
testcase_71 AC 242 ms
52,036 KB
testcase_72 AC 240 ms
51,968 KB
testcase_73 AC 239 ms
53,992 KB
testcase_74 AC 240 ms
56,148 KB
testcase_75 AC 239 ms
56,048 KB
testcase_76 AC 239 ms
56,132 KB
testcase_77 AC 238 ms
54,024 KB
testcase_78 AC 61 ms
23,616 KB
testcase_79 AC 62 ms
21,872 KB
testcase_80 AC 239 ms
56,240 KB
testcase_81 AC 241 ms
54,084 KB
testcase_82 AC 238 ms
56,156 KB
testcase_83 AC 205 ms
53,752 KB
testcase_84 AC 485 ms
74,676 KB
testcase_85 AC 1,508 ms
130,324 KB
testcase_86 AC 903 ms
92,780 KB
testcase_87 AC 702 ms
84,992 KB
testcase_88 AC 105 ms
29,512 KB
testcase_89 AC 84 ms
25,380 KB
testcase_90 TLE -
testcase_91 AC 174 ms
45,056 KB
testcase_92 AC 120 ms
31,196 KB
testcase_93 AC 1,823 ms
141,156 KB
testcase_94 AC 906 ms
96,000 KB
testcase_95 AC 634 ms
78,160 KB
testcase_96 AC 447 ms
65,640 KB
testcase_97 AC 116 ms
31,064 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 & (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);
	}
}
0