Submission #1287355

#TimeUsernameProblemLanguageResultExecution timeMemory
1287355hehehe147Topical (NOI23_topical)C++20
100 / 100
343 ms125980 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 1e6 + 7; int n, k; vector<vector<int>> r, u; void read() { cin >> n >> k; r = u = vector<vector<int>>(n + 1, vector<int>(k + 1)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> r[i][j]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { cin >> u[i][j]; } } } ll p[MAXN], cnt[MAXN]; vector<pair<int, int>> tp[MAXN]; int pt[MAXN]; void addM(int i) { for (int j = 1; j <= k; j++) { p[j] += u[i][j]; } } bool hehe() { bool flag = false; for (int i = 1; i <= k; i++) { while (pt[i] < tp[i].size() && p[i] >= tp[i][pt[i]].first) { int idx = tp[i][pt[i]].second; cnt[idx]++; if (cnt[idx] == k) { addM(idx); flag = true; } pt[i]++; } } return flag; } void solve() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { tp[j].push_back({r[i][j], i}); } } for (int i = 1; i <= k; i++) { sort(tp[i].begin(), tp[i].end()); } // for (int i = 1; i <= k; i++) { // cout << i << ": \n"; // for (auto [x, id] : tp[i]) { // cout << x << " " << id << "\n"; // } // } while (hehe()); int ans = 0; for (int i = 1; i <= n; i++) { ans += (cnt[i] == k); } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("topic.inp", "r")) { freopen("topic.inp", "r", stdin); freopen("topic.out", "w", stdout); } read(); solve(); }

Compilation message (stderr)

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