# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893331 | Kubogi | Topical (NOI23_topical) | C++17 | 396 ms | 166056 KiB |
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;
#define int long long
#define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
const int maxn = 1e6+5;
int n, m, cnt[maxn], p[maxn];
vector<int> a[maxn], u[maxn];
vector<pair<int, int>> val[maxn];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
fileio("");
// freopen("debug.txt", "w", stderr);
cin >> n >> m;
for (int i = 0; i <= n+1; i++) {
a[i] = vector<int>(m+2, 0);
u[i] = vector<int>(m+2, 0);
}
vector<int> cur;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 0) {
cnt[i]++;
}
val[j].push_back({a[i][j], i});
}
if (cnt[i] == m) {
cur.push_back(i);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> u[i][j];
}
}
for (int j = 1; j <= m; j++) {
sort(val[j].rbegin(), val[j].rend());
while (!val[j].empty() && val[j].back().first == 0) {
val[j].pop_back();
}
}
int res = 0;
while (!cur.empty()) {
int i = cur.back(); cur.pop_back();
res++;
for (int j = 1; j <= m; j++) {
p[j] += u[i][j];
while (!val[j].empty() && val[j].back().first <= p[j]) {
int x = val[j].back().second;
val[j].pop_back();
if (++cnt[x] == m) {
cur.push_back(x);
}
}
}
}
cout << res;
return 0 ^ 0;
}
Compilation message (stderr)
# | 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... |