Submission #1087551

# Submission time Handle Problem Language Result Execution time Memory
1087551 2024-09-12T22:09:10 Z I_am_Polish_Girl Let's Win the Election (JOI22_ho_t3) C++14
28 / 100
2386 ms 2420 KB
#pragma target("arch=icelake-server")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,sse4,popcnt")

#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>

using namespace std;


int log_ = 3;
int inf = 200000000000000;
int mod = 1102024631;

int p = 505;


bool cmp(pair <int, int> a, pair <int, int> b)
{
    if (a.second < b.second)
    {
        return true;
    }

    return false;
}


double dp1[501][501];

vector <pair <int, int>> vp;

int k;


vector <double> ans__;

double c(int col)
{
    if (ans__[col] != -1)
        return ans__[col];

    int n = vp.size();


    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            dp1[i][j] = inf;
        }
    }

    dp1[0][0] = 0;


    for (int k = 0; k < n; k++)
    {
        for (int i = n; i >= 0; i--)
        {
            for (int j = n; j >= 0; j--)
            {
                if (i > 0)
                {
                    if (vp[k].second != -1)
                    {
                        dp1[i][j] = min(dp1[i][j], dp1[i - 1][j] + ((0. + (col + 1) * vp[k].second) / i));
                    }
                }

                if (j > 0)
                {
                    dp1[i][j] = min(dp1[i][j], dp1[i][j - 1] + ((0. + vp[k].first)));
                }
            }
        }

    }

    double ans = inf;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (i + j == k)
            {
                if (i == col)
                {
                    ans = min(dp1[i][j], ans);
                }
            }
        }
    }

    ans /= col + 1;

    ans__[col] = ans;

    return ans;
}

mt19937 rnd(15);

int rnd_(int l, int r)
{
    int s = r - l + 1;

    int x = rnd();

    x = abs(x);

    x %= (s + 1);

    return l + x;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n >> k;

    ans__.resize(n + 2, -1);

    vp.resize(n);

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;

        vp[i] = { a,  b };
    }

    sort(vp.begin(), vp.end(), cmp);

    int l = 0;
    int r = n;

    for (int i = 0; i < n; i++)
    {
        if (vp[i].second == -1)
            r--;
    }

    int sq = sqrt(r);
    r = min(sq+10, r);
    r = min(r, k);

    
    while (r - l > 1)
    {
        int m = (l + r) /2;
        
        if (c(m) < c(m + 1))
            r = m;
        else
            l = m+1;
    }

    double ans = inf;

    for (int i = l; i <= r; i++)
    {
        ans = min(c(i) , ans);
    }


    cout << fixed;
    cout << setprecision(9);
    cout << ans;
}

Compilation message

Main.cpp:1: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    1 | #pragma target("arch=icelake-server")
      | 
Main.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      | 
Main.cpp:26:11: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000000' to '552894464' [-Woverflow]
   26 | int inf = 200000000000000;
      |           ^~~~~~~~~~~~~~~
# 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 344 KB Output is correct
5 Correct 87 ms 2416 KB Output is correct
6 Correct 88 ms 2392 KB Output is correct
7 Correct 88 ms 2396 KB Output is correct
8 Correct 88 ms 2396 KB Output is correct
9 Correct 87 ms 2396 KB Output is correct
10 Correct 96 ms 2396 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 344 KB Output is correct
5 Correct 87 ms 2416 KB Output is correct
6 Correct 88 ms 2392 KB Output is correct
7 Correct 88 ms 2396 KB Output is correct
8 Correct 88 ms 2396 KB Output is correct
9 Correct 87 ms 2396 KB Output is correct
10 Correct 96 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 2357 ms 2416 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 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 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 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 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 472 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 556 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 472 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 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 472 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 556 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 472 KB Output is correct
41 Correct 14 ms 856 KB Output is correct
42 Correct 12 ms 860 KB Output is correct
43 Correct 13 ms 868 KB Output is correct
44 Incorrect 14 ms 860 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2386 ms 2420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 344 KB Output is correct
5 Correct 87 ms 2416 KB Output is correct
6 Correct 88 ms 2392 KB Output is correct
7 Correct 88 ms 2396 KB Output is correct
8 Correct 88 ms 2396 KB Output is correct
9 Correct 87 ms 2396 KB Output is correct
10 Correct 96 ms 2396 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 2357 ms 2416 KB Output isn't correct
13 Halted 0 ms 0 KB -