답안 #883916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883916 2023-12-06T11:43:00 Z macneil Let's Win the Election (JOI22_ho_t3) C++17
28 / 100
242 ms 604 KB
//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

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) {
      |                         ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 112 ms 344 KB Output is correct
13 Incorrect 75 ms 472 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 452 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 7 ms 348 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 452 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 7 ms 348 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 8 ms 348 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 8 ms 600 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 10 ms 352 KB Output is correct
26 Correct 12 ms 604 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 348 KB Output is correct
29 Correct 8 ms 348 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 9 ms 348 KB Output is correct
33 Correct 9 ms 348 KB Output is correct
34 Correct 9 ms 352 KB Output is correct
35 Correct 9 ms 548 KB Output is correct
36 Correct 10 ms 348 KB Output is correct
37 Correct 11 ms 348 KB Output is correct
38 Correct 12 ms 348 KB Output is correct
39 Correct 12 ms 456 KB Output is correct
40 Correct 10 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 452 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 6 ms 348 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 7 ms 348 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 8 ms 348 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 8 ms 600 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 10 ms 352 KB Output is correct
26 Correct 12 ms 604 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 348 KB Output is correct
29 Correct 8 ms 348 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 9 ms 348 KB Output is correct
33 Correct 9 ms 348 KB Output is correct
34 Correct 9 ms 352 KB Output is correct
35 Correct 9 ms 548 KB Output is correct
36 Correct 10 ms 348 KB Output is correct
37 Correct 11 ms 348 KB Output is correct
38 Correct 12 ms 348 KB Output is correct
39 Correct 12 ms 456 KB Output is correct
40 Correct 10 ms 348 KB Output is correct
41 Correct 10 ms 348 KB Output is correct
42 Correct 13 ms 468 KB Output is correct
43 Correct 12 ms 344 KB Output is correct
44 Correct 17 ms 468 KB Output is correct
45 Incorrect 24 ms 348 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 242 ms 472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 112 ms 344 KB Output is correct
13 Incorrect 75 ms 472 KB Output isn't correct
14 Halted 0 ms 0 KB -