Submission #1039049

#TimeUsernameProblemLanguageResultExecution timeMemory
1039049Shadow1Topical (NOI23_topical)C++17
100 / 100
405 ms137964 KiB
// Programmer: Shadow1 #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using str = string; // yay python! #define i64 int64_t #define watch(x) cerr << (#x) << " = " << (x) << '\n'; #define output_vector(v) for(auto &x : v){cout << x << " ";}cout << '\n'; #define vt vector #define st stack #define pq priority_queue #define pb push_back #define eb emplace_back #define pii pair<int,int> #define umap unordered_map #define uset unordered_set #define fir first #define sec second #define sz(x) int(x.size()) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() // T: O(n^3) // M : O(n + k log n) void solve() { int n, k; cin >> n >> k; vector<vector<int>> r(n), u(n); vector<vector<pair<int,int>>> s(k); vector<int64_t> p(k); vector<int> c(n), ind(k,1); for(int i=0; i<n; ++i) { for(int j=0; j<k; ++j) { int x; cin >> x; r[i].push_back(x); } } for(int i=0; i<n; ++i) { for(int j=0; j<k; ++j) { int x; cin >> x; u[i].push_back(x); } } for(int j=0; j<k; ++j) { for(int i=0; i<n; ++i) { s[j].push_back({r[i][j],i}); if(r[i][j] == 0) ++c[i]; } } for(auto &S : s) sort(all(S)); int ans = 0; bool one = 0; queue<int> q; for(int i=0; i<n; ++i) { if(c[i] == k) { one = 1; q.push(i); } } while(!q.empty()) { ++ans; int cur = q.front(); q.pop(); for(int j=0; j<k; ++j) p[j] += u[cur][j]; for(int j=0; j<k; ++j) { for(int i=ind[j]; i<n; ++i) { if(s[j][i].fir <= p[j]) { ++ind[j]; ++c[s[j][i].sec]; if(c[s[j][i].sec] == k) q.push(s[j][i].sec); } else break; } } } cout << ans << '\n'; } int main() { // freopen("output.txt", "w", stdout); // freopen("input.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; } /* CHECK : 1. COMPARATOR FUNCTION MUST RETURN FALSE WHEN ARGUMENTS ARE EQUAL!!! 2. Overflow! Typecase int64_t on operations if varaibles are int 3. Check array bounds!!! 4. Check array indexing!!! 5. Edge cases. (N==1)!!! */

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:62:7: warning: variable 'one' set but not used [-Wunused-but-set-variable]
   62 |  bool one = 0;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...