帮我调刚才比赛T3
  • 板块学术版
  • 楼主Perfect_Youth
  • 当前回复6
  • 已保存回复6
  • 发布时间2025/1/19 18:01
  • 上次更新2025/1/19 20:44:32
查看原帖
帮我调刚才比赛T3
725816
Perfect_Youth楼主2025/1/19 18:01

rt.

#include <bits/stdc++.h>
#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;

using namespace std;

const int N = 27;

int t, n, a[N], m, opt[N], id1[N], id2[N];

int vis[N], cnt, vis1[N], vis2[N], tmpvis[N], tmpvis1[N], tmpvis2[N], vis3[N], tmpvis3[N], vis4[N], tmpvis4[N];

bool flag, f1[N], f2[N];

inline
int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + (ch ^ '0');
		ch = getchar();
	}
	return x * f;
}

int main() {
	t = read(), n = read();
	for (int i = 1; i <= n; i++) {
		a[i] = read();
		if (a[i] == 4) {
			vis1[i] = 1, vis2[i] = 1;
			tmpvis1[i] = 1, tmpvis2[i] = 1;
		}
		if (a[i] == 3) {
			vis3[i] = 1;
			tmpvis3[i] = 1;
		}
	}
	for (int ls = 1; ls <= t; ls++) {
		m = read();
		cnt = 0, flag = 1;
		memset(f1, 1, sizeof f1);
		memset(f2, 1, sizeof f2);
		for (int i = 1; i <= n; i++) {
			if (a[i] == 1) {
				vis4[i] = 1;
				tmpvis4[i] = 1;
			}
		}
		for (int yw = 1; yw <= m; yw++) {
			opt[yw] = read(), id1[yw] = read(), id2[yw] = read();
			if (a[id1[yw]] == 2 || id1[yw] < 1 || id2[yw] < 1 || id1[yw] > n || id2[yw] > n) flag = 0;
			if (!flag) continue;
			if (!opt[yw]) {
				if (id2[yw] == id1[yw]) {
					flag = 0;
					continue;
				}
				if (vis[id2[yw]] || vis[id1[yw]] || vis4[id1[yw]] <= 0) {
					flag = 0;
					continue;
				}
				vis[id2[yw]] = ls;
				vis4[id1[yw]]--;
			} else if (opt[yw] == 1) {
				if (id2[yw] == id1[yw]) {
					flag = 0;
					while (1);
					continue;
				}
				if (vis[id2[yw]] || vis1[id1[yw]] <= 0 || vis[id1[yw]]) {
					flag = 0;
					continue;
				}
				vis[id2[yw]] = ls;
				vis1[id1[yw]]--;
				f1[id1[yw]] = 0;
			} else if (opt[yw] == 2) {
				if (vis[id2[yw]] != ls || vis2[id1[yw]] <= 0) {
					flag = 0;
					continue;
				}
				vis[id2[yw]] = -1;
				vis2[id1[yw]]--;
				f2[id1[yw]] = 0;
			} else {
				if (id2[yw] == id1[yw]) {
					flag = 0;
					continue;
				}
				if (vis[id1[yw]] != ls || vis[id2[yw]] || vis3[id1[yw]] <= 0) {
					flag = 0;
					continue;
				}
				vis[id2[yw]] = ls;
				vis3[id1[yw]]--;
			}
		}
		for (int i = 1; i <= n; i++) {
			if (a[i] == 4) {
				if (!f1[i] && !f2[i]) {
					flag = 0;
					break;
				}
			}
		}
		if (!flag) {
			puts("Wrong");
			for (int i = 1; i <= n; i++) {
				vis[i] = tmpvis[i];
				vis1[i] = tmpvis1[i];
				vis2[i] = tmpvis2[i];
				vis3[i] = tmpvis3[i];
				vis4[i] = tmpvis4[i];
			}
		} else {
			bool flag = 1;
			for (int i = 1; i <= n; i++) {
				if (vis[i] == ls && a[i] == 3) {
					if (vis3[i]) {
						flag = 0;
						break;
					}
				}
			}
			if (!flag) {
				puts("Wrong");
				continue;
			}
			for (int i = 1; i <= n; i++) {
				if (vis[i] == ls) cnt++;
			}
			if (!cnt) {
				puts("Safe");
				continue;
			}
			printf ("%d ", cnt);
			for (int i = 1; i <= n; i++) {
				if (vis[i] == ls) printf ("%d ", i);
			}
			puts("");
			for (int i = 1; i <= n; i++) {
				tmpvis[i] = vis[i];
				tmpvis1[i] = vis1[i];
				tmpvis2[i] = vis2[i];
				tmpvis3[i] = vis3[i];
				tmpvis4[i] = vis4[i];
			}
		}
	}
	return 0;
}
2025/1/19 18:01
加载中...