답안 #854912

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


int n, k, I;
const int N = 507;
int A[N], B[N];
vector <pii> vA;
ld odpowiedz;
bool wziete[N];


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++;
        vA.push_back({A[i], i});
    }
    I = min(I, k);
    sort(vA.begin(), vA.end());


    for(int i=1; i<=k; i++)
    {
        odpowiedz += (ld) vA[i-1].f;
    }

    cout << odpowiedz << endl;


    for(int i=1; i<=I; i++)
    {
        vector <pii> ciagA;
        for(int j=1; j<=n; j++) ciagA.push_back(vA[j-1]);
        ld wynik = 0;

        for(int j=1; j<=i; j++)
        {
            ld minWyn = 10000000;
            int kto = -1;
            for(int o=1; o<=n; o++)
            {
                if(wziete[o] or B[o] == -1) continue;

                ld tmp = ((ld) B[o] / (ld) j);
                if(A[o] <= ciagA[k-i-1].f) tmp += ((ld)(ciagA[k-i].f - A[o]) / (ld)(i+1));

                //cout << "tmp = " << ((ld)(ciagA[k-i].f - A[o]) / (ld)(i+1)) << endl;
                if(minWyn > tmp)
                {
                    minWyn = tmp;
                    kto = o;
                }
            }

            //cout << "kto = " << kto << endl;
            wziete[kto] = true;
            wynik += (ld) B[kto] /(ld) j;
            for(int o=0; o<ciagA.size(); o++)
            {
                pii v = ciagA[o];
                if(v.s == kto)
                {
                    ciagA.erase(ciagA.begin() + o);
                }
            }
        }

        ld sumaA = 0;
        for(int j=1; j<=k-i; j++)
        {
            sumaA += (ld) ciagA[j-1].f;
        }
        sumaA /= (ld)(i+1);
        odpowiedz = min(odpowiedz, wynik + sumaA);
        //cout << "wynik " << i << " = " << wynik << ", suma = " << sumaA << endl;
        for(int j=1; j<=n; j++) wziete[j] = false;
    }

    cout << fixed << setprecision(5) << odpowiedz;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for(int o=0; o<ciagA.size(); o++)
      |                          ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 198 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -