이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<vector<ll>> r(n, vector<ll>(k)), u(n, vector<ll>(k));
vector<vector<pair<ll, int>>> P(k);
int ans = 0;
queue<int> q;
vector<ll> sum(k);
vector<int> cnt(n), pt(k);
vector<bool> vis(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
cin >> r[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
cin >> u[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
P[j].push_back(make_pair(r[i][j], i));
}
}
for (int i = 0; i < k; ++i) {
sort(P[i].begin(), P[i].end());
}
int rt = -1;
for (int i = 0; i < n; ++i) {
bool al = true;
for (int j = 0; j < k; ++j) {
if (r[i][j] > 0) {
al = false;
break;
}
}
if (al) {
rt = i;
break;
}
}
if (rt == -1) {
cout << "0" << "\n";
return 0;
}
q.push(rt);
while (!q.empty()) {
int nw = q.front();
q.pop();
if (vis[nw]) continue;
vis[nw] = true;
ans++;
for (int j = 0; j < k; ++j) {
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;
}
# | 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... |