답안 #853055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853055 2023-09-23T11:15:27 Z mkorzybski Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
305 ms 179508 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define ld long double


int n, k, I;
ld odpowiedz = 10000000;
const int N = 507, dupsko = 213769420;
int A[N], B[N];
ld kosztB[N][N];
int maxA[N][N];
int nextMaxA[N][N];
vector <int> ciagA[N][N];
int sumaA[N][N];
vector <pii> tab = {{-10,-10}};


bool cmpB(pii a, pii b)
{
    return a.s < b.s;
}

bool cmpA(int a, int b)
{
    return tab[a].f < tab[b].f;
}

void ustal_odp()
{
    vector <int> tmpA;
    ld tmpOdp = 0;
    for(int i=1; i<=n; i++) tmpA.push_back(A[i]);
    sort(tmpA.begin(), tmpA.end());

    for(int i=0; i<k; i++)
    {
        tmpOdp += tmpA[i];
    }

    odpowiedz = tmpOdp;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    for(int i=1; i<=n; i++)
    {
        cin >> A[i] >> B[i];
        if(B[i] != -1) I++;
        else B[i] = dupsko;
        tab.push_back({A[i], B[i]});
    }
    I = min(I, k);
    sort(tab.begin(), tab.end(), cmpB);

    /*cout << "tab\n";
    for(pii v : tab) cout << v.f << "," << v.s << "  ";
    cout << endl;*/

    ustal_odp();

    for(int i=1; i<=n; i++)
    {
        if(tab[i].s == dupsko)
        {
            kosztB[1][i] = dupsko/2;
            sumaA[1][i] = dupsko/2;
            continue;
        }

        for(int j=1; j<=n; j++)
        {
            ciagA[1][i].push_back(j);
        }
        ciagA[1][i].push_back(0);
        sort(ciagA[1][i].begin(), ciagA[1][i].end(), cmpA);

        int tmpS = ciagA[1][i].size();
        for(int j=1; j<tmpS; j++)
        {
            if(ciagA[1][i][j] == i)
            {
                ciagA[1][i].erase(ciagA[1][i].begin() + j);
                break;
            }
        }

        maxA[1][i] = ciagA[1][i][k-1];
        for(int j=1; j<=k-1; j++) sumaA[1][i] += tab[ciagA[1][i][j]].f;
        kosztB[1][i] = (ld) tab[i].s;

        odpowiedz = min(odpowiedz, kosztB[1][i] + (ld) ((ld) sumaA[1][i] /(ld) 2));

        /*cout << "dla " << 1 << ", " << i << ":\n";
        cout << sumaA[1][i] << " " << fixed << setprecision(2) << kosztB[1][i] << " " << maxA[1][i] << " {";
        for(int v : ciagA[1][i]) cout << v << ",";
        cout << "} oraz wyn = " << fixed << setprecision(3) << kosztB[1][i] + (ld) ((ld) sumaA[1][i] /(ld) 2) << endl;*/
    }

    for(int i=2; i<=I; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(tab[j].s == dupsko)
            {
                kosztB[i][j] = (ld) dupsko;
                sumaA[i][j] = (ld) dupsko;
                continue;
            }

            ld minWynik = 10000000;
            int ktoMinWynik = -1;
            for(int o=1; o<j; o++)
            {
                
                if(kosztB[i-1][o] == dupsko) continue;
                
                ld tmpWynik = kosztB[i-1][o] + (ld) ((ld) sumaA[i-1][o] /(ld) (i+1));

                if(tab[maxA[i-1][o]].f >= tab[j].f)
                {
                    tmpWynik -= (ld) tab[j].f /(ld) (i+1);
                }
                else
                {
                    tmpWynik -= (ld) tab[maxA[i-1][o]].f / (ld) (i+1);
                }
                

                if(tmpWynik < minWynik)
                {
                    minWynik = tmpWynik;
                    ktoMinWynik = o;
                }
            }
            
            

            if(ktoMinWynik == -1)
            {
                kosztB[i][j] = (ld) dupsko;
                sumaA[i][j] = (ld) dupsko;
                continue;
            }
            kosztB[i][j] = kosztB[i-1][ktoMinWynik] + (ld)((ld)tab[j].s / (ld)i);
            ciagA[i][j] = ciagA[i-1][ktoMinWynik];
            int tmpS = ciagA[i][j].size();
            for(int o=1; o<tmpS; o++)
            {
                if(ciagA[i][j][o] == j)
                {
                    ciagA[i][j].erase(ciagA[i][j].begin() + o);
                    break;
                }
            }
            for(int o=1; o<=k-i; o++)
            {
                sumaA[i][j] += tab[ciagA[i][j][o]].f;
            }
            maxA[i][j] = ciagA[i][j][k-i];

            
            odpowiedz = min(odpowiedz, kosztB[i][j] + (ld) ((ld) sumaA[i][j] /(ld) (i+1)));

            /*cout << "dla " << i << ", " << j << ":\n";
            cout << sumaA[i][j] << " " << fixed << setprecision(2) << kosztB[i][j] << " " << maxA[i][j] << " {";
            for(int v : ciagA[i][j]) cout << v << ",";
            cout << "} oraz wyn = " << fixed << setprecision(3) << kosztB[i][j] + (ld) ((ld) sumaA[i][j] /(ld) (i+1)) << endl;*/
        }
    }

    /*cout << "ciagA:\n";
    for(int i=1; i<=I; i++)
    {
        for(int j=1; j<=n; j++)
        {
            cout << "{";
            for(int v : ciagA[i][j]) cout << v << ",";
            cout << "} ";
        }
        cout << endl;
    }*/

    cout << fixed << setprecision(7) << odpowiedz;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10632 KB Output is correct
10 Correct 2 ms 10596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10632 KB Output is correct
10 Correct 2 ms 10596 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 232 ms 119260 KB Output is correct
13 Correct 110 ms 68692 KB Output is correct
14 Correct 18 ms 20060 KB Output is correct
15 Correct 242 ms 173908 KB Output is correct
16 Correct 87 ms 81956 KB Output is correct
17 Correct 19 ms 19464 KB Output is correct
18 Correct 303 ms 179036 KB Output is correct
19 Correct 96 ms 85748 KB Output is correct
20 Correct 17 ms 18520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 3 ms 10588 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10720 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10724 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 3 ms 10588 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10720 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10724 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10716 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10596 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 2 ms 10976 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 10732 KB Output is correct
31 Correct 2 ms 10844 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Incorrect 2 ms 10584 KB Output isn't correct
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 3 ms 10588 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10720 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10724 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10716 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10584 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10596 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 2 ms 10976 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 10732 KB Output is correct
31 Correct 2 ms 10844 KB Output is correct
32 Correct 2 ms 10584 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Incorrect 2 ms 10584 KB Output isn't correct
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 305 ms 179508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10632 KB Output is correct
10 Correct 2 ms 10596 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 232 ms 119260 KB Output is correct
13 Correct 110 ms 68692 KB Output is correct
14 Correct 18 ms 20060 KB Output is correct
15 Correct 242 ms 173908 KB Output is correct
16 Correct 87 ms 81956 KB Output is correct
17 Correct 19 ms 19464 KB Output is correct
18 Correct 303 ms 179036 KB Output is correct
19 Correct 96 ms 85748 KB Output is correct
20 Correct 17 ms 18520 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 2 ms 10584 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 2 ms 10588 KB Output is correct
28 Correct 2 ms 10588 KB Output is correct
29 Correct 2 ms 10720 KB Output is correct
30 Correct 2 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 10724 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10588 KB Output is correct
37 Correct 2 ms 10716 KB Output is correct
38 Correct 2 ms 10588 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10584 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 2 ms 10588 KB Output is correct
44 Correct 3 ms 10596 KB Output is correct
45 Correct 2 ms 10584 KB Output is correct
46 Correct 2 ms 10588 KB Output is correct
47 Correct 2 ms 10588 KB Output is correct
48 Correct 2 ms 10976 KB Output is correct
49 Correct 2 ms 10588 KB Output is correct
50 Correct 2 ms 10732 KB Output is correct
51 Correct 2 ms 10844 KB Output is correct
52 Correct 2 ms 10584 KB Output is correct
53 Correct 2 ms 10588 KB Output is correct
54 Correct 2 ms 10588 KB Output is correct
55 Correct 2 ms 10588 KB Output is correct
56 Correct 2 ms 10588 KB Output is correct
57 Correct 2 ms 10584 KB Output is correct
58 Incorrect 2 ms 10584 KB Output isn't correct
59 Halted 0 ms 0 KB -