제출 #824355

#제출 시각아이디문제언어결과실행 시간메모리
824355PoonYaPatLet's Win the Election (JOI22_ho_t3)C++14
56 / 100
2566 ms4324 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef pair<ld,ld> pii;

int n,k;
ld ans=1e9,a[505],b[505],dp[505][505];
vector<pii> v;

void check(ld want) {
    for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j) dp[i][j]=1e9;
    dp[0][0]=0;

    for (int i=0; i<=k; ++i) {
        if (i) {
            for (int j=0; j<=want; ++j) {
                if (j!=0 && b[i]!=1e9) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+b[i]/j); //choose B
                if (j!=want) dp[i][j]=min(dp[i][j],dp[i-1][j]+a[i]/(want+1)); //choose A
            }
        }

        ld sum=0;
        priority_queue<ld> q;
        for (int j=i+1; j<=n; ++j) {
            q.push(a[j]);
            sum+=a[j];
            if (q.size()>k-i) {
                sum-=q.top();
                q.pop();
            }
        }

        if (dp[i][(int)(want)]<1000000) ans=min(ans,dp[i][(int)(want)]+sum/(want+1));
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k;
    for (int i=0; i<n; ++i) {
        ld a,b; cin>>a>>b;
        if (b!=-1) v.push_back(pii(b,a));
        else v.push_back(pii(1e9,a));
    }
    sort(v.begin(),v.end());
    for (int i=1; i<=n; ++i) a[i]=v[i-1].second, b[i]=v[i-1].first;
    for (int i=0; i<=k; ++i) check(i);
    cout<<setprecision(15)<<ans;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void check(ld)':
Main.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (q.size()>k-i) {
      |                 ~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...