Submission #883916

#TimeUsernameProblemLanguageResultExecution timeMemory
883916macneilLet's Win the Election (JOI22_ho_t3)C++17
28 / 100
242 ms604 KiB
//cf meowcneil; t.me/macneilbot #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <bitset> #include <iterator> #include <iomanip> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <ctime> #include <deque> #include <queue> #include <stack> #include <random> #include <cassert> using namespace std; #define int long long #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define f(a) for(int i = 0; i<a; ++i) typedef long long ll; typedef unsigned long long ull; typedef double ld; typedef string str; typedef vector<str> vestr; typedef vector<int> vei; typedef vector<vector<int>> veve; mt19937 rnd(1329); const int NUM = 2e4; int k; bool flip(int a, int b) { return ((rnd() % (a + b))) < a; } ld cost(vector<int> &a, vector<int> &b, vector<int> &inb, vector<int> &ord1) { int n = a.size(); ld ans = 0; vector<int> auu; for (int i = 0; i < n; ++i) { if (inb[i]) { auu.push_back(i); } } sort(all(auu), [&](int i, int j){ return b[i] < b[j];}); for (int i = 0; i < auu.size(); ++i) { ans += (ld)(b[auu[i]]) / (i + 1); } int ctt = auu.size(); for (auto i : ord1) { if (ctt == k) break; if (!inb[i]) { ans += (ld)a[i] / (auu.size() + 1); ctt++; } } return ans; } void solve() { int n; cin >> n >> k; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; // for (int i = 0; i < n; ++i) if (b[i] == -1) b[i] = 1e14; vector<int> ord1(n), ord2(n); iota(all(ord1), 0); iota(all(ord2), 0); sort(all(ord1), [&](int i, int j){ return a[i] < a[j]; }); sort(all(ord2), [&](int i, int j){ if (b[i] == b[j]) return a[i] > a[j]; return b[i] < b[j]; }); vector<int> notminusone; for (int i = 0; i < n; ++i) if (b[i] != -1) notminusone.push_back(i); ld ans = 0; for (int i = 0; i < k; ++i) ans += a[ord1[i]]; if (notminusone.size() == 0) { cout << ans; return; } vector<int> inb(n); ld prevans = ans; for (int i = 0; i < NUM; ++i) { vector<int> tt; for (int j = 0; j < rnd() % 10 + 1; ++j) { tt.push_back(rnd() % (notminusone.size())); inb[notminusone[tt[j]]] ^= 1; } if (cost(a, b, inb, ord1) < prevans) { prevans = cost(a, b, inb, ord1); ans = min(ans, prevans); } else { for (auto e : tt) inb[notminusone[e]] ^= 1; } } cout << ans << '\n'; } signed main() { int tc = 1; cout << fixed << setprecision(15); #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> tc; #else ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin >> tc; #endif for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }

Compilation message (stderr)

Main.cpp: In function 'bool flip(long long int, long long int)':
Main.cpp:45:32: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   45 |     return ((rnd() % (a + b))) < a;
      |            ~~~~~~~~~~~~~~~~~~~~^~~
Main.cpp: In function 'ld cost(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
Main.cpp:58:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < auu.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:101:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for (int j = 0; j < rnd() % 10 + 1; ++j) {
      |                         ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...