답안 #674852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674852 2022-12-26T10:53:28 Z guagua0407 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
304 ms 3764 KB
/*
希望全國賽不要墊底

全國賽策略:
0:00-0:15:讀題
0:15-3:00:寫掉有把握的
3:00-5:00:撈分+寫掉快好的

記得上廁所
記得吃東西
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end() 
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

struct node{
    int a,b;
};

const int mxn=505;
node num[mxn];

bool cmp(node x,node y){
    if(x.b!=y.b) return x.b<y.b;
    return x.a<y.a;
}

int main() {_
    //setIO("wayne");
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>num[i].a>>num[i].b;
        if(num[i].b==-1) num[i].b=1e9;
    }
    sort(num+1,num+n+1,cmp);
    vector<vector<int>> pre(n+1,vector<int>(n+1,0));
    for(int i=0;i<=n;i++){
        vector<int> tmp;
        for(int j=i+1;j<=n;j++){
            tmp.push_back(num[j].a);
        }
        sort(all(tmp),greater<int>());
        for(int j=1;j<=n-i;j++){
            pre[i][j]=pre[i][j-1]+tmp.back();
            tmp.pop_back();
        }
    }
    double ans=(double)(1e9);
    for(int m=0;m<k;m++){
        vector<vector<double>> dp(n+1,vector<double>(m+1,(double)1e9));
        dp[0][0]=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=m;j++){
                dp[i][j]=dp[i-1][j]+(double)num[i].a/(double)(m+1);
                if(j>=1) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(double)num[i].b/(double)j);
            }
        }
        for(int i=m;i<=k;i++){
            ans=min(ans,dp[i][m]+(double)pre[i][k-i]/(double)(m+1));
            //cout<<i<<' '<<m<<' '<<fixed<<setprecision(9)<<dp[i][m]+(double)pre[i][k-i]/(double)(m+1)<<'\n';
        }
    }
    cout<<fixed<<setprecision(9);
    cout<<ans;
    return 0;
}
//maybe its multiset not set

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 5 ms 1564 KB Output is correct
6 Correct 19 ms 2212 KB Output is correct
7 Correct 72 ms 2536 KB Output is correct
8 Correct 146 ms 3364 KB Output is correct
9 Correct 266 ms 3628 KB Output is correct
10 Correct 142 ms 3108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 5 ms 1564 KB Output is correct
6 Correct 19 ms 2212 KB Output is correct
7 Correct 72 ms 2536 KB Output is correct
8 Correct 146 ms 3364 KB Output is correct
9 Correct 266 ms 3628 KB Output is correct
10 Correct 142 ms 3108 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 26 ms 2128 KB Output is correct
13 Correct 27 ms 2124 KB Output is correct
14 Correct 29 ms 2156 KB Output is correct
15 Correct 133 ms 3096 KB Output is correct
16 Correct 130 ms 3128 KB Output is correct
17 Correct 137 ms 3136 KB Output is correct
18 Correct 259 ms 3764 KB Output is correct
19 Correct 272 ms 3652 KB Output is correct
20 Correct 271 ms 3708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 448 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 596 KB Output is correct
53 Correct 2 ms 448 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 3664 KB Output is correct
2 Correct 272 ms 3628 KB Output is correct
3 Correct 304 ms 3668 KB Output is correct
4 Correct 262 ms 3608 KB Output is correct
5 Correct 276 ms 3712 KB Output is correct
6 Correct 283 ms 3592 KB Output is correct
7 Correct 285 ms 3608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 5 ms 1564 KB Output is correct
6 Correct 19 ms 2212 KB Output is correct
7 Correct 72 ms 2536 KB Output is correct
8 Correct 146 ms 3364 KB Output is correct
9 Correct 266 ms 3628 KB Output is correct
10 Correct 142 ms 3108 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 26 ms 2128 KB Output is correct
13 Correct 27 ms 2124 KB Output is correct
14 Correct 29 ms 2156 KB Output is correct
15 Correct 133 ms 3096 KB Output is correct
16 Correct 130 ms 3128 KB Output is correct
17 Correct 137 ms 3136 KB Output is correct
18 Correct 259 ms 3764 KB Output is correct
19 Correct 272 ms 3652 KB Output is correct
20 Correct 271 ms 3708 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 324 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 328 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 324 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 320 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 320 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 448 KB Output is correct
69 Correct 2 ms 468 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 2 ms 596 KB Output is correct
72 Correct 2 ms 596 KB Output is correct
73 Correct 2 ms 448 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 2 ms 468 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 266 ms 3664 KB Output is correct
82 Correct 272 ms 3628 KB Output is correct
83 Correct 304 ms 3668 KB Output is correct
84 Correct 262 ms 3608 KB Output is correct
85 Correct 276 ms 3712 KB Output is correct
86 Correct 283 ms 3592 KB Output is correct
87 Correct 285 ms 3608 KB Output is correct
88 Correct 8 ms 1564 KB Output is correct
89 Correct 9 ms 1564 KB Output is correct
90 Correct 22 ms 1996 KB Output is correct
91 Correct 22 ms 2032 KB Output is correct
92 Correct 76 ms 2528 KB Output is correct
93 Correct 75 ms 2728 KB Output is correct
94 Correct 156 ms 3044 KB Output is correct
95 Correct 148 ms 3228 KB Output is correct
96 Correct 234 ms 3452 KB Output is correct
97 Correct 219 ms 3600 KB Output is correct
98 Correct 133 ms 3072 KB Output is correct
99 Correct 131 ms 3064 KB Output is correct
100 Correct 130 ms 3128 KB Output is correct
101 Correct 157 ms 2948 KB Output is correct
102 Correct 132 ms 3060 KB Output is correct
103 Correct 133 ms 3040 KB Output is correct
104 Correct 131 ms 3064 KB Output is correct
105 Correct 128 ms 3064 KB Output is correct