This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |