Submission #1135948

#TimeUsernameProblemLanguageResultExecution timeMemory
1135948agrim_09Topical (NOI23_topical)C++20
100 / 100
465 ms103152 KiB
// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n'; #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define py cout << "YES" << endl; #define pn cout << "NO" << endl; #define pb push_back #define int long long typedef long double lld; #define double lld typedef long long ll; typedef unsigned long long ull; const ll inf = 1e18; const ll mod = 1e9+7; const int N = 2e5; vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; // Check for queue, priorioty_queue, stack, ordered_set solutions // stack => LIFO (whatever goes in last comes out last) // queue => FIFO (whatever goes in first comes out first) // priority_queue => Dynamic queries of minimum/maximum // ordered_set => set in vector form //[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element] // To comment multiple lines : ctrl + / // To find and replace : ctrl+H void judge(){ srand(time(NULL)); #ifndef ONLINE_JUDGE freopen("1.txt","r",stdin); freopen("2.txt","w",stdout); freopen("Error.txt", "w", stderr); #define debug(x...) cerr << #x <<" = "; _print(x); cerr << endl; #else #define debug(x...) #endif } void usaco(string s) { freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } signed main(){ fastio; //judge(); int n,k; cin >> n >> k; int answer = 0; vector<vector<int>>inc(n,vector<int>(k)); vector<vector<pair<int,int>>>a(k); vector<int>curr(k,0); for(int i = 0;i<n;i++){ for(int j = 0;j<k;j++){ int x; cin >> x; pair<int,int>p = {x,i}; a[j].pb(p); } } for(int i = 0;i<k;i++){ sort(a[i].begin(),a[i].end()); // for(int j = 0;j<n;j++){ // cout << a[i][j].second << ' '; // } // cout << endl; } for(int i = 0;i<n;i++){ for(int j = 0;j<k;j++){ cin >> inc[i][j]; } } priority_queue<pair<int,int>>pq; vector<int>cnt(n); vector<int>powers(k,0LL); int count = 1; while(true){ for(int i = 0;i<k;i++){ if(curr[i]==n){ continue; } pair<int,int>tmp = {powers[i],inf}; auto it = lower_bound(a[i].begin()+curr[i],a[i].end(),tmp); int idx = it - a[i].begin() - 1; for(int j = curr[i];j<=idx;j++){ cnt[a[i][j].second]++; pq.push({cnt[a[i][j].second],a[i][j].second}); } curr[i] = idx+1; } int delta = 0; while(true){ if(pq.size()==0){ break; } pair<int,int>p = pq.top(); //cout << p.first << ' ' << p.second << endl; if(cnt[p.second]!=p.first){ pq.pop(); } else{ if(p.first==k){ //cout << p.second << endl; answer++; //py; for(int j = 0;j<k;j++){ powers[j] += inc[p.second][j]; } // for(int j = 0;j<k;j++){ // cout << powers[j] << ' '; // } // cout << endl; delta = 1; pq.pop(); } else{ break; } } } if(delta==0){ break; } } // cout << endl; cout << answer << endl; }

Compilation message (stderr)

Main.cpp: In function 'void judge()':
Main.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("1.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("2.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen("Error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void usaco(std::string)':
Main.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...