답안 #971121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971121 2024-04-28T02:23:20 Z THXuan Topical (NOI23_topical) C++14
100 / 100
453 ms 174920 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
using namespace std;
typedef long long ll;

vector<pair<ll, ll>>x[1000005];

void solve()
{
	ll n, k; cin >> n >> k;
	vector<vector<ll>>v(n + 1, vector<ll>(k + 1));
	vector<vector<ll>>a(n + 1, vector<ll>(k + 1));
	int root = -1;
	for (int i = 0; i < n; i++) {
		bool flag = true;
		for (int j = 0; j < k; j++) {
			cin >> v[i][j];
			if (v[i][j] > 0)flag = false;
			x[j].push_back({ v[i][j], i });
		}
		if (flag) root = i;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			cin >> a[i][j];
		}
	}
	if (root == -1) { cout << 0 << "\n"; return; }
	for (int i = 0; i < k; i++) sort(x[i].begin(), x[i].end());
	queue<ll>q;
	q.push(root);
	ll ans = 0;
	vector<bool>visited(n, false);
	vector<ll>p(k), pos(k), seen(n);
	while (q.size()) {
		int node = q.front(); q.pop();
		if (visited[node])continue;
		visited[node] = true;
		++ans;
		for (int i = 0; i < k; i++) {
			p[i] += a[node][i];
			while (pos[i] < x[i].size() && x[i][pos[i]].first <= p[i]) {
				if (++seen[x[i][pos[i]].second] == k && !visited[x[i][pos[i]].second]) {
					q.push(x[i][pos[i]].second);
				}
				++pos[i];
			}
		}
		
	}
	cout << ans << "\n";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;// cin>>t;
	while (t--) solve();
	return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:47:18: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    while (pos[i] < x[i].size() && x[i][pos[i]].first <= p[i]) {
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24408 KB Output is correct
2 Correct 6 ms 23904 KB Output is correct
3 Correct 7 ms 24408 KB Output is correct
4 Correct 195 ms 102004 KB Output is correct
5 Correct 204 ms 102084 KB Output is correct
6 Correct 189 ms 102088 KB Output is correct
7 Correct 152 ms 86320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 23896 KB Output is correct
2 Correct 6 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 6 ms 23900 KB Output is correct
5 Correct 6 ms 23900 KB Output is correct
6 Correct 6 ms 23900 KB Output is correct
7 Correct 8 ms 24340 KB Output is correct
8 Correct 10 ms 24408 KB Output is correct
9 Correct 7 ms 24152 KB Output is correct
10 Correct 8 ms 24156 KB Output is correct
11 Correct 8 ms 24196 KB Output is correct
12 Correct 7 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23940 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 9 ms 25436 KB Output is correct
4 Correct 40 ms 37280 KB Output is correct
5 Correct 40 ms 38388 KB Output is correct
6 Correct 453 ms 174920 KB Output is correct
7 Correct 426 ms 170768 KB Output is correct
8 Correct 449 ms 174900 KB Output is correct
9 Correct 446 ms 170520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24408 KB Output is correct
2 Correct 6 ms 23904 KB Output is correct
3 Correct 7 ms 24408 KB Output is correct
4 Correct 195 ms 102004 KB Output is correct
5 Correct 204 ms 102084 KB Output is correct
6 Correct 189 ms 102088 KB Output is correct
7 Correct 152 ms 86320 KB Output is correct
8 Correct 6 ms 23896 KB Output is correct
9 Correct 6 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 6 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 8 ms 24340 KB Output is correct
15 Correct 10 ms 24408 KB Output is correct
16 Correct 7 ms 24152 KB Output is correct
17 Correct 8 ms 24156 KB Output is correct
18 Correct 8 ms 24196 KB Output is correct
19 Correct 7 ms 24156 KB Output is correct
20 Correct 5 ms 23940 KB Output is correct
21 Correct 5 ms 23896 KB Output is correct
22 Correct 9 ms 25436 KB Output is correct
23 Correct 40 ms 37280 KB Output is correct
24 Correct 40 ms 38388 KB Output is correct
25 Correct 453 ms 174920 KB Output is correct
26 Correct 426 ms 170768 KB Output is correct
27 Correct 449 ms 174900 KB Output is correct
28 Correct 446 ms 170520 KB Output is correct
29 Correct 233 ms 77908 KB Output is correct
30 Correct 221 ms 73044 KB Output is correct
31 Correct 267 ms 78820 KB Output is correct
32 Correct 199 ms 68820 KB Output is correct
33 Correct 190 ms 65772 KB Output is correct
34 Correct 214 ms 68860 KB Output is correct
35 Correct 246 ms 75768 KB Output is correct
36 Correct 216 ms 71932 KB Output is correct
37 Correct 234 ms 74752 KB Output is correct
38 Correct 176 ms 67916 KB Output is correct