제출 #1169561

#제출 시각아이디문제언어결과실행 시간메모리
1169561CDuongTopical (NOI23_topical)C++20
100 / 100
476 ms121696 KiB
/* #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt") */ #include <bits/stdc++.h> #define taskname "" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define i64 long long #define isz(x) (int)x.size() using namespace std; void solve() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); vector<vector<int>> b(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { cin >> a[i][j]; } for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { cin >> b[i][j]; } int res = 0; vector<int> process; vector<int> ptr(m), val(m), cnt(n); vector<vector<int>> idx(m, vector<int>(n)); auto update = [&]() -> void { for (int j = 0; j < m; ++j) { while (ptr[j] < n and a[idx[j][ptr[j]]][j] <= val[j]) { if (++cnt[idx[j][ptr[j]]] == m) { process.emplace_back(idx[j][ptr[j]]); } ++ptr[j]; } } }; for (int j = 0; j < m; ++j) { iota(all(idx[j]), 0); sort(all(idx[j]), [&](int x, int y) { return a[x][j] < a[y][j]; }); } do { while (not process.empty()) { int idx = process.back(); process.pop_back(); // cout << "+ " << idx << endl; for (int j = 0; j < m; ++j) val[j] += b[idx][j]; ++res; } update(); // cout << endl; } while (not process.empty()); cout << res << endl; } signed main() { #ifndef CDuongg if (fopen(taskname".inp", "r")) assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout)); #else freopen("bai3.inp", "r", stdin); freopen("bai3.out", "w", stdout); auto start = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while(t--) solve(); #ifdef CDuongg auto end = chrono::high_resolution_clock::now(); cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '='; cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...