QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#669145#9246. Dominating PointmzyxML 0ms3616kbC++201.4kb2024-10-23 17:26:042024-10-23 17:26:41

Judging History

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

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

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 >= n) {
				break;
			}
			
			for (auto y : adj[x]) {
				if (!vis[y][step + 1]) {
					q.push({y, step + 1});
				}
			}
		}
		
		// 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: 3552kb

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: 3616kb

input:

3
011
001
000

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #3:

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

input:

3
010
001
100

output:

1 2 3

result:

ok OK, Answer correct.

Test #4:

score: -100
Memory Limit Exceeded

input:

4994
0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...

output:

1 2 3

result: