Submission #862326

#TimeUsernameProblemLanguageResultExecution timeMemory
862326quandlmTopical (NOI23_topical)C++17
100 / 100
585 ms233888 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
#define pi pair<int,int>
#define ple tuple<int,int,int>
#define fi first
#define se second
#define ii make_pair
#define isz(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()

using namespace std;

const int N = 1e6 + 10;

int n,k;
int p[N], cnt[N];
vector<vector<int>> a,b;
priority_queue<pi,vector<pi>,greater<pi>> pq[N];

int main () {
      file("seq");
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

      cin >> n >> k;
      a.assign(n+10,vector<int>(k+10));
      b.assign(n+10,vector<int>(k+10));
      FOR(i,1,n) {
          FOR(j,1,k) {
              cin >> a[i][j];
              pq[j].push({a[i][j], i});
          }
      }
      FOR(i,1,n) {
          FOR(j,1,k) cin >> b[i][j];
      }
      int res = 0;
      while(1) {
            vector<int> solved = {};
            FOR(j,1,k) {
                while(!pq[j].empty() && p[j] >= pq[j].top().fi) {
                      pi it = pq[j].top(); pq[j].pop();
                      cnt[it.se]++;
                      if (cnt[it.se] == k) {
                          solved.push_back(it.se);
                      }
                }
            }
            for (int i : solved) {
                 FOR(j,1,k) {
                       p[j] += b[i][j];
                 }
            }
            res += isz(solved);
            if (isz(solved) == 0) break;
      }
      cout << res << '\n';
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:2:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:7: note: in expansion of macro 'file'
   24 |       file("seq");
      |       ^~~~
Main.cpp:2:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:7: note: in expansion of macro 'file'
   24 |       file("seq");
      |       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...