QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#669188#9246. Dominating PointmzyxTL 0ms3560kbC++201.5kb2024-10-23 17:36:282024-10-23 17:36:38

Judging History

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

  • [2024-11-22 18:38:25]
  • hack成功,自动添加数据
  • (/hack/1238)
  • [2024-10-23 17:36:38]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3560kb
  • [2024-10-23 17:36:28]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	
	string g[n];
	for (int i = 0; i < n; i++) {
		cin >> g[i];
	}
	
	vector<vector<int>> adj(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (g[i][j] == '1') {
				adj[i].push_back(j);
			}
		}
	}
	
	auto bfs = [&](int u) -> bool {
		vector<vector<int>> vis(n, vector<int>(3));
		queue<pair<int, int>> q;
		q.push({u, 0});
		while (!q.empty()) {
			auto [x, step] = q.front();
			q.pop();
			
			if (vis[x][step]) {
				continue;
			}
			vis[x][step] = 1;
			if (step >= 3) {
				break;
			}
			
			for (auto y : adj[x]) {
				if (!vis[y][step + 1]) {
					q.push({y, step + 1});
				}
			}
			if (q.size() >= 40*n) {
				break;
			}
		}
		
		// cerr << "f" << "\n";
		// cerr << u << "\n";
		// for (int i = 0; i < n; i++) {
		// 	cerr << vis[i][0] << " " << vis[i][1] << "\n";
		// }
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (vis[i][0] || vis[i][1] || vis[i][2]) {
				cnt++;
			}
		}
		
		return cnt >= n;
	};
	
	vector<int> ans;
	for (int i = 0; i < n; i++) {
		if (bfs(i)) {
			ans.push_back(i + 1);
		}
		if (ans.size() >= 3) {
			break;
		}
	}
	
	if (ans.size() >= 3) {
		cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n";
	} else {
		cout << "NOT FOUND" << "\n";
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

6
011010
000101
010111
100001
010100
100010

output:

1 3 4

result:

ok OK, Answer correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3
011
001
000

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

3
010
001
100

output:

1 2 3

result:

ok OK, Answer correct.

Test #4:

score: -100
Time Limit Exceeded

input:

4994
0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...

output:


result: