QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567789#9319. Bull Farmlmx111RE 0ms0kbC++202.4kb2024-09-16 13:55:512024-09-16 13:55:54

Judging History

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

  • [2024-09-16 13:55:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-16 13:55:51]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
#define endl '\n'
using namespace std;
int z[2009][2009];
int cur[2009];
int du[2009];
bool w[2009][2009];
bool vis[2009];
vector<pair<int,int>>zzz[2009];
priority_queue<pair<int, int>> qqq;
void solve() {
	int n, l, q;
	cin >> n >> l >> q;
	getchar();
	for (int i = 1; i <= n; i++) {
		zzz[i].clear();
		for (int j = 1; j <= n; j++) {
			z[i][j] = 1000000000000000;
			w[i][j] = 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		w[i][i] = 1;
	}
	for (int i = 1; i <= l; i++) {
		for (int i = 1; i <= n; i++) {
			du[i] = 0;
			cur[i] = 0;
		}
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= 2; k++) {
				cur[j] *= 50;
				char a = getchar();
				cur[j] += a - '0';
			}
		}
		getchar();
		for (int k = 1; k <= n; k++) {
			du[cur[k]]++;
		}
		int flag1 = 0, flag2 = 0;
		for (int k = 1; k <= n; k++) {
			if (du[k] != 1) {
				flag1++;
			}
			if (du[k] == 0) {
				flag2 = k;
			}
		}
		if (flag1 == 0) {
			for (int k = 1; k <= n; k++) {
				if (w[k][cur[k]]) {
					continue;
				}
				zzz[k].push_back({ -i, cur[k] });
				w[k][cur[k]] = 1;
			}
		}
		else {
			if (flag1 == 2) {
				for (int k = 1; k <= n; k++) {
					if (du[cur[k]] == 2 && w[k][flag2] == 0) {
						zzz[k].push_back({ -i, flag2 });
						w[k][flag2] = 1;
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int i = 1; i <= n; i++) {
			vis[i] = 0;
		}
		qqq.push({ 0, i });
		while (!qqq.empty()) {
			pair<int, int> u = qqq.top();
			qqq.pop();
			if (vis[u.second] == 1)
				continue;
			z[i][u.second] = -u.first;
			vis[u.second] = 1;
			for (auto ed : zzz[u.second]) {
				int www = ed.first, v = ed.second;
				if (vis[v] == 1)
					continue;
				qqq.push({ -max(z[i][u.second],-www), v });
			}
		}
	}
	for (int i = 1; i <= q; i++) {
		int u = 0;
		for (int k = 1; k <= 2; k++) {
			u *= 50;
			char a = getchar();
			u += a - '0';
		}
		int v = 0;
		for (int k = 1; k <= 2; k++) {
			v *= 50;
			char a = getchar();
			v += a - '0';
		}
		int w = 0;
		for (int k = 1; k <= 2; k++) {
			w *= 50;
			char a = getchar();
			w += a - '0';
		}
		getchar();
		if (z[u][v] <= w) {
			putchar('1');
		}
		else {
			putchar('0');
		}
	}
	putchar('\n');
}
signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:


result: