Submission #1268349

#TimeUsernameProblemLanguageResultExecution timeMemory
1268349shirokitoTopical (NOI23_topical)C++20
100 / 100
338 ms80188 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, k; cin >> n >> k; vector<ll> cnt_ok(n + 1), cur(k + 1); vector<vector<pair<ll, ll>>> a(k + 1); vector<vector<ll>> b(n + 1, vector<ll> (k + 1, 0)); queue<int> q; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { int x; cin >> x; if (x == 0) cnt_ok[i]++; else a[j].push_back({x, i}); } if (cnt_ok[i] == k) { q.push(i); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> b[i][j]; } } for (int i = 1; i <= k; i++) { sort(a[i].begin(), a[i].end(), greater<>()); } int res = 0; while (q.size()) { int x = q.front(); q.pop(); res++; for (int j = 1; j <= k; j++) { cur[j] += b[x][j]; } for (int j = 1; j <= k; j++) { while (a[j].size() && a[j].back().first <= cur[j]) { int p = a[j].back().second; a[j].pop_back(); cnt_ok[p]++; if (cnt_ok[p] == k) { q.push(p); } } } } cout << res << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); #define task "topic" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int T = 1; // cin >> T; while (T--) { solve(); } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(task".out", "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...