Submission #929243

#TimeUsernameProblemLanguageResultExecution timeMemory
929243okkooTopical (NOI23_topical)C++17
100 / 100
861 ms123136 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; const int mxn = 1e6; int can[mxn]; bool compare(pair<int, int> a, pair<int, int> b){ if(a.first == b.first) return a.second < b.second; return a.first > b.first; } int main(){ int n, k; cin >> n >> k; vector<vector<int> > require(n, vector<int>(k)), gain(n, vector<int>(k)); queue<int> q; vector<vector<pair<int, int> > > tmp(k, vector<pair<int, int> >()); vector<long long> knowledge(k, 0); for(int i=0; i<n; i++){ for(int j=0; j<k; j++){ cin >> require[i][j]; if(!require[i][j]) can[i]++; tmp[j].push_back(make_pair(require[i][j], i)); } if(can[i]==k) q.push(i); } for(int i=0; i<n; i++){ for(int j=0; j<k; j++) cin >> gain[i][j]; } for(int i=0; i<k; i++){ sort(tmp[i].begin(), tmp[i].end(), compare); } int ans = 0; while(!q.empty()){ int cur = q.front(); q.pop(); ans++; for(int i=0; i<k; i++){ knowledge[i] += gain[cur][i]; while(!tmp[i].empty() && tmp[i].back().first <= knowledge[i]){ int module = tmp[i].back().second; can[module]++; if(can[module] == k) q.push(module); tmp[i].pop_back(); } } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...