結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー kwm_tkwm_t
提出日時 2023-05-20 10:59:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,237 ms / 2,000 ms
コード長 5,677 bytes
コンパイル時間 2,864 ms
コンパイル使用メモリ 220,340 KB
実行使用メモリ 62,900 KB
最終ジャッジ日時 2024-12-21 09:34:27
合計ジャッジ時間 43,558 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 873 ms
19,276 KB
testcase_02 AC 1,045 ms
31,604 KB
testcase_03 AC 943 ms
31,636 KB
testcase_04 AC 946 ms
33,268 KB
testcase_05 AC 997 ms
34,504 KB
testcase_06 AC 1,046 ms
50,292 KB
testcase_07 AC 1,038 ms
51,320 KB
testcase_08 AC 1,048 ms
54,784 KB
testcase_09 AC 1,237 ms
54,164 KB
testcase_10 AC 978 ms
34,292 KB
testcase_11 AC 1,038 ms
31,988 KB
testcase_12 AC 1,045 ms
32,892 KB
testcase_13 AC 1,027 ms
33,664 KB
testcase_14 AC 1,050 ms
33,564 KB
testcase_15 AC 1,029 ms
33,140 KB
testcase_16 AC 1,047 ms
32,888 KB
testcase_17 AC 1,049 ms
32,832 KB
testcase_18 AC 1,043 ms
32,072 KB
testcase_19 AC 1,036 ms
32,040 KB
testcase_20 AC 1,033 ms
31,892 KB
testcase_21 AC 1,138 ms
60,076 KB
testcase_22 AC 1,133 ms
60,828 KB
testcase_23 AC 1,151 ms
60,292 KB
testcase_24 AC 1,167 ms
62,900 KB
testcase_25 AC 1,148 ms
61,468 KB
testcase_26 AC 1,159 ms
59,336 KB
testcase_27 AC 1,155 ms
62,244 KB
testcase_28 AC 1,150 ms
60,220 KB
testcase_29 AC 1,159 ms
60,476 KB
testcase_30 AC 1,145 ms
59,796 KB
testcase_31 AC 564 ms
59,556 KB
testcase_32 AC 561 ms
61,076 KB
testcase_33 AC 561 ms
61,732 KB
testcase_34 AC 589 ms
59,496 KB
testcase_35 AC 597 ms
60,968 KB
testcase_36 AC 593 ms
62,484 KB
testcase_37 AC 73 ms
6,820 KB
testcase_38 AC 1,046 ms
32,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct trie {
	int kind;
	vector<int>node;
	vector<vector<int>>next;
	vector<bool>end;
	trie(int _kind) :kind(_kind) {
		node.resize(1);
		end.resize(1);
		next.emplace_back(vector<int>(kind, -1));
	}
	void insert(const vector<int>&v) {
		int now = 0;
		rep(i, v.size()) {
			if (-1 == next[now][v[i]]) {
				next[now][v[i]] = node.size();
				node.emplace_back(0);
				end.push_back(false);
				next.emplace_back(vector<int>(kind, -1));
			}
			now = next[now][v[i]];
			node[now]++;
		}
		end[now] = true;
	}
	// prefixも投入する
	void insertEx(const vector<int>&v) {
		int now = 0;
		rep(i, v.size()) {
			if (-1 == next[now][v[i]]) {
				next[now][v[i]] = node.size();
				node.emplace_back(0);
				next.emplace_back(vector<int>(kind, -1));
			}
			now = next[now][v[i]];
			node[now] += v.size() - i;
			end[now] = true;
		}
	}
	// 1-indexed
	vector<int>kth_element(int k) {
		int now = 0;
		vector<int>ret;
		while (true) {
			bool flag = false;
			rep(i, kind) {
				if (-1 == next[now][i])continue;
				if (k <= node[next[now][i]]) {
					flag = true;
					ret.emplace_back(i);
					now = next[now][i];
					break;
				}
				else {
					k -= node[next[now][i]];
				}
			}
			if (!flag)break;
		}
		return ret;
	}
	bool seach(const vector<int>&v) {
		int now = 0;
		rep(i, v.size()) {
			if (-1 == next[now][v[i]])return false;
			if (node[next[now][v[i]]] <= 0)return false;
			now = next[now][v[i]];
		}
		return end[now];
	}
	void erase(const vector<int>&v) {
		int now = 0;
		rep(i, v.size()) {
			now = next[now][v[i]];
			node[now]--;
		}
		end[now] = false;
	}
	// GetIndex
	int getIndex(const vector<int>&v) {
		int ret = 0, now = 0;
		rep(i, v.size()) {
			if (0 != now) {
				ret += node[now];
				rep(j, 2)if (-1 != next[now][j])ret -= node[next[now][j]];
			}
			if (0 == v[i]) {
				if (-1 == next[now][v[i]])break;
				now = next[now][v[i]];
			}
			else {
				if (-1 != next[now][0]) ret += node[next[now][0]];
				if (-1 == next[now][v[i]])break;
				now = next[now][v[i]];
			}
		}
		return ret;
	}
	// prefixも取得する
	vector<int> getIndexEx(const vector<int>&v) {
		vector<int>ret;
		int idx = 0, now = 0;
		rep(i, v.size()) {
			if (0 != now) {
				idx += node[now];
				rep(j, 2)if (-1 != next[now][j])idx -= node[next[now][j]];
			}
			if (0 == v[i]) {
				if (-1 == next[now][v[i]])break;
				now = next[now][v[i]];
			}
			else {
				if (-1 != next[now][0]) idx += node[next[now][0]];
				if (-1 == next[now][v[i]])break;
				now = next[now][v[i]];
			}
			ret.push_back(idx);
		}
		return ret;
	}
	// Binary Trie
	vector<int>xor_max(const vector<int>&v) {
		vector<int>ret;
		int now = 0;
		rep(i, v.size()) {
			vector<int>tmp = { 1 - v[i],v[i] };
			rep(j, tmp.size()) {
				if (-1 == next[now][tmp[j]])continue;
				if (node[next[now][tmp[j]]] <= 0)continue;
				ret.emplace_back(tmp[j]);
				now = next[now][tmp[j]];
				break;
			}
		}
		return ret;
	}
	vector<int>xor_min(const vector<int>&v) {
		vector<int>ret;
		int now = 0;
		rep(i, v.size()) {
			vector<int>tmp = { v[i],1 - v[i] };
			rep(j, tmp.size()) {
				if (-1 == next[now][tmp[j]])continue;
				if (node[next[now][tmp[j]]] <= 0)continue;
				ret.emplace_back(tmp[j]);
				now = next[now][tmp[j]];
				break;
			}
		}
		return ret;
	}
	// xとxorした結果がk未満になる物の数(0含む)
	int xor_count(const vector<int>&x, const vector<int>&k) {
		int ret = 0, now = 0;
		rep(i, k.size()) {
			if (0 == k[i]) {
				if (-1 == next[now][x[i]])break;
				now = next[now][x[i]];
			}
			else {
				if (-1 != next[now][x[i]])ret += node[next[now][x[i]]];
				if (-1 == next[now][1 - x[i]])break;
				now = next[now][1 - x[i]];
			}
		}
		return ret;
	}
};
// Binary Trie
vector<int> trans(long long n, int sz = 30) {
	vector<int>ret(sz, 0);
	rep(i, sz) {
		if (1 & (n >> i))ret[sz - 1 - i] = 1;
	}
	return ret;
}
long long inverse(const vector<int>&v) {
	long long ret = 0;
	rep(i, v.size()) {
		ret *= 2;
		ret += v[i];
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		vector<bool>a(n);
		vector<string>b(n - 1);
		rep(i, n) {
			string s; cin >> s;
			if ("True" == s)a[i] = 1;
		}
		rep(i, n - 1)cin >> b[i];
		trie tra(2);
		rep(i, n) tra.insert(trans(i));
		trie trb(2);
		rep(i, n - 1) trb.insert(trans(i));
		rep(i, n - 1) {
			int t; cin >> t, t--;
			auto p = inverse(tra.kth_element(t + 1));
			auto q = inverse(tra.kth_element(t + 2));
			auto x = inverse(trb.kth_element(t + 1));
			if ("and" == b[x]) {
				a[p] = a[p] & a[q];
			}
			else if("or" == b[x]) {
				a[p] = a[p] | a[q];
			}
			else if("xor" == b[x]) {
				a[p] = a[p] ^ a[q];
			}
			else {
				a[p] = (a[p] ? a[q] : true);
			}
			tra.erase(trans(q));
			trb.erase(trans(x));

		}
		if (a[0])cout << "True" << endl;
		else cout << "False" << endl;
	}
	return 0;
}
0