답안 #973977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973977 2024-05-02T14:10:12 Z berr Let's Win the Election (JOI22_ho_t3) C++17
16 / 100
209 ms 4448 KB
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 505;
     
    double dp[N][N], mi[N][N];
     
    signed main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        
        int n, k; cin >> n >> k;
     
        vector<array<int, 2>> a(n);
     
        for(auto &[i, l]: a) cin >> i >> l;
     
        sort(a.begin(), a.end(), [&](auto x, auto y){
            if(x[1]==y[1]) return x[0] < y[0];
            else if(y[1]==-1) return true;
            else if(x[1]==-1) return false;
             return x[1]<y[1]; 
        });
     
        double ans=1e9;

        for(int i=0; i<=n; i++){
            for(int l=0; l<=n; l++){
                mi[i][l]=1e9;
            }
        }
        mi[n][0]=0;

        for(int i=n-1; i>=0; i--){
            mi[i][0]=0;

            for(int l=n; l>0; l--){

                mi[i][l]=min(mi[i][l], mi[i+1][l-1]+a[i][0]);
               /// cout<<mi[i+1][l-1]<<" "<<mi[i][l]<<"\n";
            }
        }


        auto calc=[&](int e){
           
            for(int i=0; i<=n+1; i++){
                for(int l=0; l<=n+1; l++){
                    dp[i][l]=1e9;
                }
            }
         
            dp[0][0]=0;
            for(int i=0; i<n; i++){
                if(a[i][1]==-1) break;
                dp[i][0]=(i==0?0:dp[i-1][0])+(double)a[i][0]/(double)(e+1);
                if(i>0)
                    for(int l=e; l>=1; l--)
                    dp[i][l] =min<double>(dp[i-1][l-1]+(double)a[i][1]/(double)(l), dp[i-1][l]+((double)a[i][0])/(double)(e+1)); 
                
                else dp[i][1]=a[i][1], dp[i][0]=(double)a[i][0]/(e+1);
                
            }

            for(int i=0; i<n; i++){
                if(mi[i+1][k-i-1]!=1e9)
                ans=min(ans, dp[i][e]+(double)mi[i+1][k-i-1]/(double)(e+1));
            }

        };


        for(int i=1; i<=k; i++){
            calc(i);
        }

        ans=min(ans, mi[0][k]);

        cout<<setprecision(9)<<ans<<"\n";
        
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 10 ms 4440 KB Output is correct
6 Correct 22 ms 4444 KB Output is correct
7 Correct 42 ms 4416 KB Output is correct
8 Correct 72 ms 4440 KB Output is correct
9 Correct 82 ms 4188 KB Output is correct
10 Correct 59 ms 4420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 10 ms 4440 KB Output is correct
6 Correct 22 ms 4444 KB Output is correct
7 Correct 42 ms 4416 KB Output is correct
8 Correct 72 ms 4440 KB Output is correct
9 Correct 82 ms 4188 KB Output is correct
10 Correct 59 ms 4420 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 35 ms 4448 KB Output is correct
13 Incorrect 31 ms 4188 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 4416 KB Output is correct
2 Correct 188 ms 4188 KB Output is correct
3 Correct 179 ms 4184 KB Output is correct
4 Correct 209 ms 4444 KB Output is correct
5 Correct 209 ms 4440 KB Output is correct
6 Correct 185 ms 4184 KB Output is correct
7 Correct 181 ms 4420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 10 ms 4440 KB Output is correct
6 Correct 22 ms 4444 KB Output is correct
7 Correct 42 ms 4416 KB Output is correct
8 Correct 72 ms 4440 KB Output is correct
9 Correct 82 ms 4188 KB Output is correct
10 Correct 59 ms 4420 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 35 ms 4448 KB Output is correct
13 Incorrect 31 ms 4188 KB Output isn't correct
14 Halted 0 ms 0 KB -