Submission #1044554

#TimeUsernameProblemLanguageResultExecution timeMemory
1044554juicySightseeing in Kyoto (JOI22_kyoto)C++17
100 / 100
107 ms12224 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif using T = array<long long, 3>; bool smaller(const T &a, const T &b) { long long A = a[0] * b[1], B = a[1] * b[0]; return A == B ? a[2] < b[2] : A < B; } struct cmp { bool operator()(const T &a, const T &b) const { return smaller(a, b); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; array<vector<int>, 2> a; a[0].resize(n); a[1].resize(m); auto nxt = a; array<vector<bool>, 2> del; array<priority_queue<T, vector<T>, cmp>, 2> pq; for (auto it : {0, 1}) { del[it].resize(a[it].size()); iota(nxt[it].begin(), nxt[it].end(), 1); for (int &x : a[it]) { cin >> x; } for (int i = 0; i + 1 < a[it].size(); ++i) { pq[it].push({a[it][i + 1] - a[it][i], 1, i}); } } long long res = 0; auto pop = [&](int it, vector<int> &nxt) { auto [_, cnt, l] = pq[it].top(); pq[it].pop(); int r = nxt[l]; if (r + 1 == a[it].size()) { while (cnt--) { a[it].pop_back(); res += a[it ^ 1].back(); } } else { int k = nxt[r]; del[it][r] = 1; nxt[l] = k; pq[it].push({a[it][k] - a[it][l], k - l, l}); } }; auto upd = [&](priority_queue<T, vector<T>, cmp> &pq, vector<bool> &del) { while (pq.size() && del[pq.top()[2]]) { pq.pop(); } }; while (pq[0].size() || pq[1].size()) { if (!pq[0].size()) { pop(1, nxt[1]); } else if (!pq[1].size()) { pop(0, nxt[0]); } else if (smaller(pq[0].top(), pq[1].top())) { pop(1, nxt[1]); } else { pop(0, nxt[0]); } upd(pq[0], del[0]); upd(pq[1], del[1]); } cout << res; return 0; }

Compilation message (stderr)

kyoto.cpp: In function 'int main()':
kyoto.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i + 1 < a[it].size(); ++i) {
      |                         ~~~~~~^~~~~~~~~~~~~~
kyoto.cpp: In lambda function:
kyoto.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if (r + 1 == a[it].size()) {
      |             ~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...