답안 #914894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914894 2024-01-22T20:21:46 Z andrei_iorgulescu Let's Win the Election (JOI22_ho_t3) C++14
0 / 100
837 ms 2824 KB
#include <bits/stdc++.h>

using namespace std;
using ld = long double;

#define int long long

int n,k;
ld m;
ld a[505],b[505];
ld v[505];

int better(int x,int y,ld t)
{
    ld p1 = v[y] + b[x] / t,p2 = v[x] + b[y] / t;
    //cout << x << ' ' << y << ' ' << t << ' ' << p1 << ' ' << p2 << endl;
    if (p1 < p2)
        return x;
    //cout << y << endl;
    return y;
}

ld solve(int pos,vector<int>ids)
{
    if (pos == m + 1)
    {
        vector<ld>as;
        for (auto it : ids)
            as.push_back(v[it]);
        sort(as.begin(),as.end());
        ld adg = 0;
        for (int i = 0; i < k - m + 1; i++)
            adg += as[i];
        return adg;
    }
    int opt = 0;
    for (int i = 1; i < ids.size(); i++)
    {
        int bt = better(ids[i],ids[opt],pos - 1);
        if (bt == ids[i])
            opt = i;
    }
    //cout << opt << ' ' << ids[opt] << endl;
    ld pz = pos - 1;
    ld adg = b[ids[opt]] / pz;
    vector<int>newids;
    for (int i = 0; i < opt; i++)
        newids.push_back(ids[i]);
    for (int i = opt + 1; i < ids.size(); i++)
        newids.push_back(ids[i]);
    return adg + solve(pos + 1,newids);
}

signed main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
    for (int i = 1; i <= n; i++)
        if (b[i] == -1)
            b[i] = 1e7;
    ld ans = 1e5;
    for (m = 1; m <= k; m++)
    {
        ///m oameni workpower, apoi doar merg prin orase
        for (int i = 1; i <= n; i++)
            v[i] = a[i] / m;
        vector<int>ids;
        for (int i = 1; i <= n; i++)
            ids.push_back(i);
        ld cur = solve(2,ids);
        //cout << cur << endl;
        ans = min(ans,cur);
    }
    cout << setprecision(5) << fixed;
    cout << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'ld solve(long long int, std::vector<long long int>)':
Main.cpp:37: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]
   37 |     for (int i = 1; i < ids.size(); i++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:49:29: 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]
   49 |     for (int i = opt + 1; i < ids.size(); i++)
      |                           ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 99 ms 1456 KB Output is correct
7 Correct 350 ms 2224 KB Output is correct
8 Incorrect 685 ms 2660 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 99 ms 1456 KB Output is correct
7 Correct 350 ms 2224 KB Output is correct
8 Incorrect 685 ms 2660 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 0 ms 440 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 837 ms 2824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 17 ms 896 KB Output is correct
6 Correct 99 ms 1456 KB Output is correct
7 Correct 350 ms 2224 KB Output is correct
8 Incorrect 685 ms 2660 KB Output isn't correct
9 Halted 0 ms 0 KB -