QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463234#8770. Comparatorstd_abs#WA 0ms3812kbC++203.7kb2024-07-04 16:16:312024-07-04 16:16:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 16:16:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-07-04 16:16:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 1e9 + 7, N = 100000;

struct ST {
	vector <vector <pii>> val;
	ST (vector <pii> a) {
		int n = a.size();
		int g = __lg(n) + 1;
		val.assign(g, vector <pii>(n));
		for (int i = 0; i < n; ++i) {
			val[0][i] = a[i];
		}
		for (int j = 1; j < g; ++j) {
			for (int i = 0; i + (1 << j) <= n; ++i) {
				val[j][i] = min(val[j - 1][i], val[j - 1][i + (1 << j - 1)]);
			}
		}
	}
	pii query(int l, int r) {
		int cg = __lg(r - l);
		return min(val[cg][l], val[cg][r - (1 << cg)]);
	}
};

vector <pii> solve(string s) {
	int n = s.size();
	vector <pii> val(n);
	for (int i = 0; i < n; ++i) {
		if (i) {
			val[i] = val[i - 1];
		}
		if (s[i] == '(') {
			val[i].first++;
			val[i].second = 6 * n + i;
		} else if (s[i] == ')') {
			val[i].first--;
			val[i].second = 6 * n + i;
		} else if (s[i] == '!') {
			val[i].second = 5 * n + i;
		} else if (s[i] == '=') {
			val[i].second = 4 * n + i;
		} else if (s[i] == '&') {
			val[i].second = 3 * n + i;
		} else if (s[i] == '|') {
			val[i].second = 2 * n + i;
		} else if (s[i] == '^') {
			val[i].second = 1 * n + i;
		} else {
			val[i].second = 7 * n + i;
		}
	}
	ST DS(val);

	auto solve = [&](auto self, int l, int r, int vx, int vy) -> int {
		if (r - l == 1) {
			if (s[l] == 'x') {
				return vx;
			} else if (s[l] == 'y') {
				return vy;
			} else {
				assert('0' <= s[l] && s[l] <= '1');
				return s[l] - '0';
			}
		}
		auto [dep, id] = DS.query(l, r);
		int type = id / n, pos = id % n;
		if (type == 1) {
			return self(self, l, pos, vx, vy) ^ self(self, pos + 1, r, vx, vy);
		} else if (type == 2) {
			return self(self, l, pos, vx, vy) | self(self, pos + 1, r, vx, vy);
		} else if (type == 3) {
			return self(self, l, pos, vx, vy) & self(self, pos + 1, r, vx, vy);
		} else if (type == 4) {
			return self(self, l, pos, vx, vy) == self(self, pos + 1, r, vx, vy);
		} else if (type == 5) {
			assert(pos == l);
			return self(self, l + 1, r, vx, vy) ^ 1;
		} else {
			assert(s[l] == '(' && s[r - 1] == ')');
			return self(self, l + 1, r - 1, vx, vy);
		}
	};
	
	vector <pii> res;
	for (int vx : {0, 1}) for (int vy : {0, 1}) {
		if (solve(solve, 0, n, vx, vy) == 1) {
			res.emplace_back(vx, vy);
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector vis(2 * k, vector <int>(2 * k, false));
	vector <array <int, 5>> events;
	for (int i = 0; i < n; ++i) {
		int a, b; string s; int r;
		cin >> a >> b >> s >> r, --a, --b;
		auto res = solve(s);
		for (auto [x, y] : res) {
			int nx = a + x * k, ny = b + y * k;
			if (!vis[nx][ny]) {
				vis[nx][ny] = true;
				events.pb({a, x, b, y, r});
			}
		}
	}
	cout << endl;
	int final; cin >> final;
	vector table(1 << k, vector <int>(1 << k, final));
	vector <bitset <1024>> row(1 << k), col(1 << k);
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		for (auto [px, vx, py, vy, r] : events) {
			if ((x >> px & 1) == vx && (y >> py & 1) == vy) {
				table[x][y] = r;
				break;
			}
		}
		if (table[x][y]) {
			row[x][y] = 1, col[y][x] = 1;
		}
	}

	int cnt[3] = {0, 0, 0};
	for (int x = 0; x < 1 << k; ++x) if (table[x][x]) {
		cnt[0]++;
	}
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		if (table[x][y] == 1 && table[y][x] == 1) {
			cnt[1]++;
		}
	}
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		if (table[x][y] == 0) {
			cnt[2] += (row[x] & col[y]).count();
		}
	}

	cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3812kb

input:

3 2
1 1 (x=0)&(y=1) 1
1 1 (x=1)&(y=(x^x)) 0
2 2 (x=1)|(y=0) 0
1

output:


0 0 0

result:

wrong answer 1st lines differ - expected: '0 0 0', found: ''