답안 #946886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946886 2024-03-15T07:12:46 Z josanneo22 Topical (NOI23_topical) C++17
100 / 100
450 ms 146828 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define L(i, j, k) for (int i = (j); i <= (k); ++i) 
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define rep0(i, n) L(i, 0, n - 1)
#define rep1(i, n) L(i, 1, n)

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

	int n, k; cin >> n >> k;
	vector<vector<i64>> r(n, vector<i64>(k)), u(n, vector<i64>(k));
	vector<vector<pair<i64, int>>> P(k);

	int ans = 0;
	queue<int> q;
	vector<i64> sum(k);
	vector<int> cnt(n), pt(k);
	vector<bool> vis(n);

	L(i, 0, n - 1) L(j, 0, k - 1) cin >> r[i][j];
	L(i, 0, n - 1) L(j, 0, k - 1) cin >> u[i][j];
	L(i, 0, n - 1) L(j, 0, k - 1) P[j].push_back(make_pair(r[i][j], i));
	L(i, 0, k - 1) sort(P[i].begin(), P[i].end());

	int root = -1;
	L(i, 0, n - 1) {
		bool all0 = true;
		L(j, 0, k - 1) if(r[i][j] > 0) all0 = false;
		if(all0) root = i;
	}

	if (root == -1) {
		cout << "0\n";
		return 0;
	}
	
	q.push(root);
	while (!q.empty()) {
		int nw = q.front(); q.pop();
		if(vis[nw]) continue;
		vis[nw] = true;
		ans++;
		L(j, 0, k - 1) {
			sum[j] += u[nw][j];
			while (pt[j] < n && P[j][pt[j]].first <= sum[j]) {
				if (++cnt[P[j][pt[j]].second] == k) q.push(P[j][pt[j]].second);
				pt[j]++;
			}
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 175 ms 88600 KB Output is correct
5 Correct 183 ms 88892 KB Output is correct
6 Correct 176 ms 88596 KB Output is correct
7 Correct 144 ms 85704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 5 ms 2140 KB Output is correct
4 Correct 35 ms 15308 KB Output is correct
5 Correct 33 ms 15260 KB Output is correct
6 Correct 430 ms 146600 KB Output is correct
7 Correct 415 ms 145080 KB Output is correct
8 Correct 450 ms 146828 KB Output is correct
9 Correct 417 ms 145660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 175 ms 88600 KB Output is correct
5 Correct 183 ms 88892 KB Output is correct
6 Correct 176 ms 88596 KB Output is correct
7 Correct 144 ms 85704 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 3 ms 980 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 2 ms 960 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 452 KB Output is correct
22 Correct 5 ms 2140 KB Output is correct
23 Correct 35 ms 15308 KB Output is correct
24 Correct 33 ms 15260 KB Output is correct
25 Correct 430 ms 146600 KB Output is correct
26 Correct 415 ms 145080 KB Output is correct
27 Correct 450 ms 146828 KB Output is correct
28 Correct 417 ms 145660 KB Output is correct
29 Correct 235 ms 55032 KB Output is correct
30 Correct 215 ms 49676 KB Output is correct
31 Correct 282 ms 55496 KB Output is correct
32 Correct 172 ms 45396 KB Output is correct
33 Correct 188 ms 42576 KB Output is correct
34 Correct 216 ms 45520 KB Output is correct
35 Correct 257 ms 51972 KB Output is correct
36 Correct 226 ms 48452 KB Output is correct
37 Correct 244 ms 51408 KB Output is correct
38 Correct 175 ms 44340 KB Output is correct