답안 #1072081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072081 2024-08-23T14:05:28 Z _rain_ Let's Win the Election (JOI22_ho_t3) C++14
10 / 100
7 ms 4220 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("");

    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 (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 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 4 ms 4220 KB Output is correct
9 Correct 5 ms 4188 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 4 ms 4220 KB Output is correct
9 Correct 5 ms 4188 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 3 ms 3932 KB Output is correct
13 Correct 2 ms 3932 KB Output is correct
14 Correct 2 ms 3932 KB Output is correct
15 Correct 4 ms 4188 KB Output is correct
16 Correct 6 ms 4188 KB Output is correct
17 Correct 4 ms 4188 KB Output is correct
18 Correct 6 ms 4188 KB Output is correct
19 Correct 5 ms 4188 KB Output is correct
20 Correct 5 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
10 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
10 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 4 ms 4220 KB Output is correct
9 Correct 5 ms 4188 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 3 ms 3932 KB Output is correct
13 Correct 2 ms 3932 KB Output is correct
14 Correct 2 ms 3932 KB Output is correct
15 Correct 4 ms 4188 KB Output is correct
16 Correct 6 ms 4188 KB Output is correct
17 Correct 4 ms 4188 KB Output is correct
18 Correct 6 ms 4188 KB Output is correct
19 Correct 5 ms 4188 KB Output is correct
20 Correct 5 ms 4188 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Incorrect 0 ms 348 KB Output isn't correct
30 Halted 0 ms 0 KB -