답안 #1072078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072078 2024-08-23T14:04:10 Z _rain_ Let's Win the Election (JOI22_ho_t3) C++14
0 / 100
2 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false
#define double long double

void SETIO(string name = ""){
    if (name=="") return;
    freopen((name+".inp").c_str(),"r",stdin);
//    freopen((name+".out").c_str(),"w",stdout);
    return;
}

const int maxn = 500;
const int maxk = 500;
const int INF = 1e9 + 7;
int n , k ;
pair<int,int> a[maxn+2];
#define fi first
#define se second

bool cmp(pair<int,int> a , pair<int,int> b){
    if (a.second != b.second) return a.second < b.second;
    return a.first < b.first;
}
double dp[maxn+2][maxk+2] , f[maxn+2];


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    SETIO("main");

    cin >> n >> k;
    for (int i = 0; i <= n + 1; ++i){
        for (int j = 0; j <= k + 1; ++j) dp[i][j] = INF;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].fi >> a[i].se;
        if (a[i].se==-1) a[i].se = INF;
    }
    sort(a+1,a+n+1,cmp);
    cout << setprecision(10) << fixed ;
    if (fixbug){
        cout << "(DEBUG)\n";
        for (int i = 1; i <= n; ++i) cout << a[i].fi << ' ' << a[i].se << '\n';
    }

    for (int i = 0; i <= n + 1; ++i) dp[i][0] = 0;
    for (int i = n; i >= 1; --i){
        dp[i][1] = a[i].first;
        for (int num = 1; num <= k; ++num){
            dp[i][num] = min(dp[i + 1][num] , dp[i][num]);
            dp[i][num] = min(dp[i][num] , dp[i + 1][num - 1] + a[i].first);
        }
    }
    f[0] = 0 ;
    double ans = dp[1][k];
    for (int i = 1; i <= k; ++i){
        f[i] = f[i - 1] + a[i].second / (double)i;
        if (k - i == 0 || a[i].second == INF) continue;
        ans = min(ans , f[i] + dp[i + 1][k - i] / (double)(i + 1));
    }
    if (fixbug){
        cout << "( FIX BUG )\n";
        for (int i = 1; i <= k; ++i) {
                cout << "(( OOO-OOO )) " << dp[i + 1][k - i] << '\n';
                cout << f[i] << ' ' << dp[i + 1][k - i] / (double)(i + 1) << "\n";
        }
    }
    cout << ans;
}

Compilation message

Main.cpp: In function 'void SETIO(std::string)':
Main.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen((name+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -