Submission #914154

#TimeUsernameProblemLanguageResultExecution timeMemory
914154LitusianoTopical (NOI23_topical)C++17
100 / 100
551 ms144152 KiB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma") #include<bits/stdc++.h> using namespace std; #define int long long bool cmp(pair<int,int> a, pair<int,int> b){ return a.second < b.second; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; vector<vector<int>> r(n,vector<int>(k,0)); auto u = r; for(auto& x : r){ for(auto& i : x) cin>>i; } for(auto& x : u){ for(auto& i : x) cin>>i; } vector<vector<pair<int,int>>> idx(k); vector<int> pt(k); for(int i = 0; i<k; i++){ for(int j = 0; j<n; j++){ idx[i].push_back({r[j][i], j}); } sort(idx[i].begin(), idx[i].end()); // can go from i to i+1 if and only if in this topic if r[i][j] + u[i][j] >= r[z][j] } queue<int> q; q.push(-1); vector<int> act(k); vector<int> used(n); vector<int> PT(k,0); int ans = 0; while(!q.empty()){ int u1 = q.front(); q.pop(); if(u1 >= 0) ans++; for(int i = 0; i<k; i++){ if(u1 >= 0) act[i] += u[u1][i]; if(PT[i] == n) continue; if(idx[i][PT[i]].first > act[i]) continue; while(PT[i] < n && idx[i][PT[i]].first <= act[i]){ // cerr<<"! "<<i<<" "<<idx[i][PT[i]].second<<endl; used[idx[i][PT[i]].second]++; // if all used, q.push if(used[idx[i][PT[i]].second] == k) q.push(idx[i][PT[i]].second); PT[i]++; } } } 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...