Submission #883915

# Submission time Handle Problem Language Result Execution time Memory
883915 2023-12-06T11:41:42 Z macneil Let's Win the Election (JOI22_ho_t3) C++17
77 / 100
981 ms 744 KB
// очень классно когда уже на втором туре сидишь сдал на 100 а твое решение тупо ломают а когда у когото n^2logn на n до 1e6 заходит всем пофиг почемуто
// тут тоже кстати можно тл в два раза обрезать чтоб не расслаблялись и отжиг на еще меньше заходил ну это так идея вам для размышления

#pragma GCC optimize("O3") 
#pragma GCC optimize("unroll-loops") 
  
// #pragma GCC optimize("Ofast,unroll-loops") 
  
// #pragma GCC optimize(3) 
// #pragma GCC optimize("Ofast") 
// #pragma GCC optimize("inline") 
// #pragma GCC optimize("-fgcse") 
// #pragma GCC optimize("-fgcse-lm") 
// #pragma GCC optimize("-fipa-sra") 
// #pragma GCC optimize("-ftree-pre") 
// #pragma GCC optimize("-ftree-vrp") 
// #pragma GCC optimize("-fpeephole2") 
// #pragma GCC optimize("-ffast-math") 
// #pragma GCC optimize("-fsched-spec") 
// #pragma GCC optimize("-falign-jumps") 
// #pragma GCC optimize("-falign-loops") 
// #pragma GCC optimize("-falign-labels") 
// #pragma GCC optimize("-fdevirtualize") 
// #pragma GCC optimize("-fcaller-saves") 
// #pragma GCC optimize("-fcrossjumping") 
// #pragma GCC optimize("-fthread-jumps") 
// #pragma GCC optimize("-freorder-blocks") 
// #pragma GCC optimize("-fschedule-insns") 
// #pragma GCC optimize("inline-functions") 
// #pragma GCC optimize("-ftree-tail-merge") 
// #pragma GCC optimize("-fschedule-insns2") 
// #pragma GCC optimize("-fstrict-aliasing") 
// #pragma GCC optimize("-falign-functions") 
// #pragma GCC optimize("-fcse-follow-jumps") 
// #pragma GCC optimize("-fsched-interblock") 
// #pragma GCC optimize("-fpartial-inlining") 
// #pragma GCC optimize("no-stack-protector") 
// #pragma GCC optimize("-freorder-functions") 
// #pragma GCC optimize("-findirect-inlining") 
// #pragma GCC optimize("-fhoist-adjacent-loads") 
// #pragma GCC optimize("-frerun-cse-after-loop") 
// #pragma GCC optimize("inline-small-functions") 
// #pragma GCC optimize("-finline-small-functions") 
// #pragma GCC optimize("-ftree-switch-conversion") 
// #pragma GCC optimize("-foptimize-sibling-calls") 
// #pragma GCC optimize("-fexpensive-optimizations") 
// #pragma GCC optimize("inline-functions-called-once") 
// #pragma GCC optimize("-fdelete-null-pointer-checks") 

#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 = 685000;
 
int k;

int gen(int n){
    return min(rnd() % n, rnd() % n);
}
 
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, vector<int> &ord2) {
    int n = a.size();
    ld ans = 0;
    vector<int> auu;
    int ttt = 1;
    for (auto i : ord2) {
        if (inb[i]) {
            ans += (ld)(b[i]) / (ttt);
            ttt++;
        }
    }
    int ctt = ttt - 1;
    for (auto i : ord1) {
        if (ctt == k) break;
        if (!inb[i]) {
            ans += (ld)a[i] / (ttt);
            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);
    sort(all(notminusone), [&](int i, int j){
        return b[i] < b[j];
    });
    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);
    // for (int i = 0; i < n; ++i) {
    //     if (b[i] == -1) continue;
    //     if (rnd() % 2 == 1) inb[i] = 1;
    // }
    inb[notminusone[notminusone.size() - 1]] = 1;
    if (ans > cost(a, b, inb, ord1, ord2)) {
        ans = cost(a, b, inb, ord1, ord2);
    }
    else {
        inb.clear();
        inb.resize(n);
    }
    ld prevans = ans;
    for (int i = 0; i < NUM; ++i) {
        vector<int> tt;
        for (int j = 0; j < rnd() % 5 + 1; ++j) {
            tt.push_back(gen(notminusone.size()));
            inb[notminusone[tt[j]]] ^= 1;
        }
        if (cost(a, b, inb, ord1, ord2) < prevans) {
            prevans = cost(a, b, inb, ord1, ord2);
            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

Main.cpp: In function 'bool flip(int, int)':
Main.cpp:96:32: warning: comparison of integer expressions of different signedness: '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'} and 'int' [-Wsign-compare]
   96 |     return ((rnd() % (a + b))) < a;
      |            ~~~~~~~~~~~~~~~~~~~~^~~
Main.cpp: In function 'ld cost(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
Main.cpp:100:9: warning: unused variable 'n' [-Wunused-variable]
  100 |     int n = a.size();
      |         ^
Main.cpp: In function 'void solve()':
Main.cpp:165:27: warning: comparison of integer expressions of different signedness: '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]
  165 |         for (int j = 0; j < rnd() % 5 + 1; ++j) {
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 83 ms 440 KB Output is correct
12 Correct 577 ms 452 KB Output is correct
13 Correct 456 ms 344 KB Output is correct
14 Correct 405 ms 448 KB Output is correct
15 Correct 681 ms 460 KB Output is correct
16 Correct 692 ms 600 KB Output is correct
17 Correct 606 ms 452 KB Output is correct
18 Correct 889 ms 456 KB Output is correct
19 Correct 967 ms 460 KB Output is correct
20 Correct 770 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 348 KB Output is correct
2 Correct 98 ms 436 KB Output is correct
3 Correct 96 ms 440 KB Output is correct
4 Correct 100 ms 440 KB Output is correct
5 Correct 106 ms 432 KB Output is correct
6 Correct 102 ms 344 KB Output is correct
7 Correct 104 ms 344 KB Output is correct
8 Correct 106 ms 440 KB Output is correct
9 Correct 103 ms 440 KB Output is correct
10 Correct 102 ms 344 KB Output is correct
11 Correct 100 ms 432 KB Output is correct
12 Correct 124 ms 436 KB Output is correct
13 Correct 103 ms 744 KB Output is correct
14 Correct 108 ms 436 KB Output is correct
15 Correct 108 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 348 KB Output is correct
2 Correct 98 ms 436 KB Output is correct
3 Correct 96 ms 440 KB Output is correct
4 Correct 100 ms 440 KB Output is correct
5 Correct 106 ms 432 KB Output is correct
6 Correct 102 ms 344 KB Output is correct
7 Correct 104 ms 344 KB Output is correct
8 Correct 106 ms 440 KB Output is correct
9 Correct 103 ms 440 KB Output is correct
10 Correct 102 ms 344 KB Output is correct
11 Correct 100 ms 432 KB Output is correct
12 Correct 124 ms 436 KB Output is correct
13 Correct 103 ms 744 KB Output is correct
14 Correct 108 ms 436 KB Output is correct
15 Correct 108 ms 348 KB Output is correct
16 Correct 117 ms 436 KB Output is correct
17 Correct 118 ms 344 KB Output is correct
18 Correct 141 ms 348 KB Output is correct
19 Correct 124 ms 348 KB Output is correct
20 Correct 125 ms 344 KB Output is correct
21 Correct 120 ms 348 KB Output is correct
22 Correct 128 ms 436 KB Output is correct
23 Correct 121 ms 344 KB Output is correct
24 Correct 120 ms 344 KB Output is correct
25 Correct 137 ms 348 KB Output is correct
26 Correct 142 ms 440 KB Output is correct
27 Correct 120 ms 344 KB Output is correct
28 Correct 120 ms 348 KB Output is correct
29 Correct 117 ms 348 KB Output is correct
30 Correct 117 ms 436 KB Output is correct
31 Correct 129 ms 348 KB Output is correct
32 Correct 129 ms 444 KB Output is correct
33 Correct 119 ms 344 KB Output is correct
34 Correct 129 ms 436 KB Output is correct
35 Correct 132 ms 344 KB Output is correct
36 Correct 131 ms 344 KB Output is correct
37 Correct 134 ms 436 KB Output is correct
38 Correct 129 ms 440 KB Output is correct
39 Correct 133 ms 436 KB Output is correct
40 Correct 126 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 348 KB Output is correct
2 Correct 98 ms 436 KB Output is correct
3 Correct 96 ms 440 KB Output is correct
4 Correct 100 ms 440 KB Output is correct
5 Correct 106 ms 432 KB Output is correct
6 Correct 102 ms 344 KB Output is correct
7 Correct 104 ms 344 KB Output is correct
8 Correct 106 ms 440 KB Output is correct
9 Correct 103 ms 440 KB Output is correct
10 Correct 102 ms 344 KB Output is correct
11 Correct 100 ms 432 KB Output is correct
12 Correct 124 ms 436 KB Output is correct
13 Correct 103 ms 744 KB Output is correct
14 Correct 108 ms 436 KB Output is correct
15 Correct 108 ms 348 KB Output is correct
16 Correct 117 ms 436 KB Output is correct
17 Correct 118 ms 344 KB Output is correct
18 Correct 141 ms 348 KB Output is correct
19 Correct 124 ms 348 KB Output is correct
20 Correct 125 ms 344 KB Output is correct
21 Correct 120 ms 348 KB Output is correct
22 Correct 128 ms 436 KB Output is correct
23 Correct 121 ms 344 KB Output is correct
24 Correct 120 ms 344 KB Output is correct
25 Correct 137 ms 348 KB Output is correct
26 Correct 142 ms 440 KB Output is correct
27 Correct 120 ms 344 KB Output is correct
28 Correct 120 ms 348 KB Output is correct
29 Correct 117 ms 348 KB Output is correct
30 Correct 117 ms 436 KB Output is correct
31 Correct 129 ms 348 KB Output is correct
32 Correct 129 ms 444 KB Output is correct
33 Correct 119 ms 344 KB Output is correct
34 Correct 129 ms 436 KB Output is correct
35 Correct 132 ms 344 KB Output is correct
36 Correct 131 ms 344 KB Output is correct
37 Correct 134 ms 436 KB Output is correct
38 Correct 129 ms 440 KB Output is correct
39 Correct 133 ms 436 KB Output is correct
40 Correct 126 ms 348 KB Output is correct
41 Correct 180 ms 436 KB Output is correct
42 Correct 152 ms 436 KB Output is correct
43 Correct 166 ms 444 KB Output is correct
44 Correct 163 ms 344 KB Output is correct
45 Correct 187 ms 344 KB Output is correct
46 Correct 224 ms 348 KB Output is correct
47 Correct 208 ms 440 KB Output is correct
48 Correct 219 ms 596 KB Output is correct
49 Correct 238 ms 440 KB Output is correct
50 Correct 241 ms 348 KB Output is correct
51 Correct 278 ms 440 KB Output is correct
52 Correct 286 ms 348 KB Output is correct
53 Correct 202 ms 548 KB Output is correct
54 Correct 188 ms 440 KB Output is correct
55 Correct 184 ms 444 KB Output is correct
56 Correct 199 ms 444 KB Output is correct
57 Correct 239 ms 436 KB Output is correct
58 Correct 235 ms 344 KB Output is correct
59 Correct 246 ms 436 KB Output is correct
60 Correct 231 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 935 ms 456 KB Output is correct
2 Correct 981 ms 592 KB Output is correct
3 Correct 951 ms 464 KB Output is correct
4 Correct 867 ms 456 KB Output is correct
5 Correct 867 ms 600 KB Output is correct
6 Correct 813 ms 500 KB Output is correct
7 Correct 887 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 83 ms 440 KB Output is correct
12 Correct 577 ms 452 KB Output is correct
13 Correct 456 ms 344 KB Output is correct
14 Correct 405 ms 448 KB Output is correct
15 Correct 681 ms 460 KB Output is correct
16 Correct 692 ms 600 KB Output is correct
17 Correct 606 ms 452 KB Output is correct
18 Correct 889 ms 456 KB Output is correct
19 Correct 967 ms 460 KB Output is correct
20 Correct 770 ms 448 KB Output is correct
21 Correct 103 ms 348 KB Output is correct
22 Correct 98 ms 436 KB Output is correct
23 Correct 96 ms 440 KB Output is correct
24 Correct 100 ms 440 KB Output is correct
25 Correct 106 ms 432 KB Output is correct
26 Correct 102 ms 344 KB Output is correct
27 Correct 104 ms 344 KB Output is correct
28 Correct 106 ms 440 KB Output is correct
29 Correct 103 ms 440 KB Output is correct
30 Correct 102 ms 344 KB Output is correct
31 Correct 100 ms 432 KB Output is correct
32 Correct 124 ms 436 KB Output is correct
33 Correct 103 ms 744 KB Output is correct
34 Correct 108 ms 436 KB Output is correct
35 Correct 108 ms 348 KB Output is correct
36 Correct 117 ms 436 KB Output is correct
37 Correct 118 ms 344 KB Output is correct
38 Correct 141 ms 348 KB Output is correct
39 Correct 124 ms 348 KB Output is correct
40 Correct 125 ms 344 KB Output is correct
41 Correct 120 ms 348 KB Output is correct
42 Correct 128 ms 436 KB Output is correct
43 Correct 121 ms 344 KB Output is correct
44 Correct 120 ms 344 KB Output is correct
45 Correct 137 ms 348 KB Output is correct
46 Correct 142 ms 440 KB Output is correct
47 Correct 120 ms 344 KB Output is correct
48 Correct 120 ms 348 KB Output is correct
49 Correct 117 ms 348 KB Output is correct
50 Correct 117 ms 436 KB Output is correct
51 Correct 129 ms 348 KB Output is correct
52 Correct 129 ms 444 KB Output is correct
53 Correct 119 ms 344 KB Output is correct
54 Correct 129 ms 436 KB Output is correct
55 Correct 132 ms 344 KB Output is correct
56 Correct 131 ms 344 KB Output is correct
57 Correct 134 ms 436 KB Output is correct
58 Correct 129 ms 440 KB Output is correct
59 Correct 133 ms 436 KB Output is correct
60 Correct 126 ms 348 KB Output is correct
61 Correct 180 ms 436 KB Output is correct
62 Correct 152 ms 436 KB Output is correct
63 Correct 166 ms 444 KB Output is correct
64 Correct 163 ms 344 KB Output is correct
65 Correct 187 ms 344 KB Output is correct
66 Correct 224 ms 348 KB Output is correct
67 Correct 208 ms 440 KB Output is correct
68 Correct 219 ms 596 KB Output is correct
69 Correct 238 ms 440 KB Output is correct
70 Correct 241 ms 348 KB Output is correct
71 Correct 278 ms 440 KB Output is correct
72 Correct 286 ms 348 KB Output is correct
73 Correct 202 ms 548 KB Output is correct
74 Correct 188 ms 440 KB Output is correct
75 Correct 184 ms 444 KB Output is correct
76 Correct 199 ms 444 KB Output is correct
77 Correct 239 ms 436 KB Output is correct
78 Correct 235 ms 344 KB Output is correct
79 Correct 246 ms 436 KB Output is correct
80 Correct 231 ms 348 KB Output is correct
81 Correct 935 ms 456 KB Output is correct
82 Correct 981 ms 592 KB Output is correct
83 Correct 951 ms 464 KB Output is correct
84 Correct 867 ms 456 KB Output is correct
85 Correct 867 ms 600 KB Output is correct
86 Correct 813 ms 500 KB Output is correct
87 Correct 887 ms 596 KB Output is correct
88 Correct 307 ms 348 KB Output is correct
89 Correct 301 ms 348 KB Output is correct
90 Correct 443 ms 460 KB Output is correct
91 Correct 365 ms 348 KB Output is correct
92 Correct 515 ms 504 KB Output is correct
93 Correct 513 ms 596 KB Output is correct
94 Correct 682 ms 452 KB Output is correct
95 Correct 704 ms 600 KB Output is correct
96 Incorrect 843 ms 456 KB Output isn't correct
97 Halted 0 ms 0 KB -