Submission #1315906

#TimeUsernameProblemLanguageResultExecution timeMemory
1315906kantaponzTopical (NOI23_topical)C++20
100 / 100
467 ms274376 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n, k; int ans = 0; int need[1000005]; int ptr[1000005]; ll p[1000005]; vector<vector<pair<ll,int>>> topic; vector<vector<ll>> r, u; void process(int j) { while (ptr[j] < n && topic[j][ptr[j]].first <= p[j]) { int i = topic[j][ptr[j]].second; need[i]--; ptr[j]++; if (!need[i]) { ans++; for (int j = 1; j <= k; j++) { p[j] += u[i][j]; process(j); } } } return; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; r.resize(n + 5, vector<ll>(k + 5, 0)); u.resize(n + 5, vector<ll>(k + 5, 0)); topic.resize(k + 5); memset(ptr, 0, sizeof ptr); fill(need, need + n + 5, k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> r[i][j]; topic[j].emplace_back(r[i][j], i); } } for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) cin >> u[i][j]; for (int j = 1; j <= k; j++) { sort(topic[j].begin(), topic[j].end()); } for (int j = 1; j <= k; j++) { process(j); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...