Submission #535056

# Submission time Handle Problem Language Result Execution time Memory
535056 2022-03-09T10:53:44 Z nathanlee726 Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
247 ms 8304 KB
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcountll((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define jimmy_is_kind false
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;

//#define LOCAL
#ifdef LOCAL
#define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif

int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);}
int sub(int a,int b){return(a<b?a+mod-b:a-b);}
int po(int a,int b){
	if(b==0)return 1;
	if(b==1)return(a%mod);
	int tem=po(a,b/2);
	if(b&1)return(((tem*tem)%mod)*a)%mod;
	else return(tem*tem)%mod;
}
int GCD(int a,int b){
	int x=0;
	int ra,rb;
	while(a&&b){
		if(((a&1)==0)&&((b&1)==0)){
			a>>=1,b>>=1,x++;
		}
		else if((a^b)&1){
			if(a&1)b>>=1;
			else a>>=1;
		}
		else{
			ra=abs(a-b),rb=min(a,b);
			a=ra,b=rb;
		}
	}
	return max(a,b)<<x;
}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int n,k;
pii pt[505],pt2[505];
vector<pii>pt1;
double dp[505][505],tdp[505][505],rd[505][505],rm[505][505];

bool cmp(pii a,pii b){
    if(a.Y==-1&&b.Y==-1){
        return a.X<b.X;
    }
    if(a.Y==-1){
        return false;
    }
    if(b.Y==-1)return true;
    return a.Y<b.Y;
}

signed main(){
	IOS();
	cin>>n>>k;
	F(n)cin>>pt[i].X>>pt[i].Y;
	sort(pt,pt+n,cmp);
	F(n)bug(pt[i].Y);
	F(n+1)Fi(j,n+1)dp[i][j]=tdp[i][j]=rd[i][j]=-1;
	bug(dp[0][0]);
	dp[0][0]=0;
	Fi(l,k){
        for(int i=0;i<n;i++){
            for(int j=0;j<=l;j++){
                if(dp[i][j]==-1)continue;
                if(pt[i].Y!=-1){
                    if(dp[i+1][j+1]!=-1)dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(((double)(pt[i].Y))/((double)(j+1))));
                    else dp[i+1][j+1]=dp[i][j]+(((double)(pt[i].Y))/((double)(j+1)));
                }
                if(dp[i+1][j]!=-1)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(((double)(pt[i].X))/((double)(l+1))));
                else dp[i+1][j]=dp[i][j]+(((double)(pt[i].X))/((double)(l+1)));
            }
        }
        for(int i=0;i<=n;i++)rm[l][i]=dp[i][l];
	}
	rd[n][0]=0;
	for(int i=n-1;i>=0;i--){
        for(int j=0;j<n;j++){
            if(rd[i+1][j]==-1)continue;
            rd[i][j]=(rd[i][j]==-1?rd[i+1][j]:min(rd[i+1][j],rd[i][j]));
            rd[i][j+1]=(rd[i][j+1]==-1?rd[i+1][j]+pt[i].X:min(rd[i][j+1],rd[i+1][j]+pt[i].X));
        }
	}
	double ans=1e18;
	F(k){
        for(int j=i;j<k;j++){
            if(rm[i][j]!=-1)ans=min(ans,rm[i][j]+((double)(rd[j][k-j]))/((double)(i+1)));
            bug(i,j,rm[i][j]);
            bug(ans);
        }
        if(rm[i][k]!=-1)ans=min(ans,rm[i][k]);
	}
	cout<<fixed<<setprecision(10);
	cout<<ans<<endl;
	return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 6 ms 6476 KB Output is correct
6 Correct 8 ms 6732 KB Output is correct
7 Correct 21 ms 7220 KB Output is correct
8 Correct 34 ms 7704 KB Output is correct
9 Correct 55 ms 8240 KB Output is correct
10 Correct 30 ms 7560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 6 ms 6476 KB Output is correct
6 Correct 8 ms 6732 KB Output is correct
7 Correct 21 ms 7220 KB Output is correct
8 Correct 34 ms 7704 KB Output is correct
9 Correct 55 ms 8240 KB Output is correct
10 Correct 30 ms 7560 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 26 ms 6812 KB Output is correct
13 Correct 22 ms 6884 KB Output is correct
14 Correct 22 ms 6860 KB Output is correct
15 Correct 110 ms 7644 KB Output is correct
16 Correct 85 ms 7548 KB Output is correct
17 Correct 56 ms 7764 KB Output is correct
18 Correct 204 ms 8224 KB Output is correct
19 Correct 155 ms 8160 KB Output is correct
20 Correct 113 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 584 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 584 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 584 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 584 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 584 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 1 ms 584 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 588 KB Output is correct
41 Correct 1 ms 1604 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 1 ms 1604 KB Output is correct
45 Correct 2 ms 1736 KB Output is correct
46 Correct 2 ms 1612 KB Output is correct
47 Correct 2 ms 1740 KB Output is correct
48 Correct 3 ms 1740 KB Output is correct
49 Correct 2 ms 1860 KB Output is correct
50 Correct 2 ms 1732 KB Output is correct
51 Correct 3 ms 1864 KB Output is correct
52 Correct 3 ms 1852 KB Output is correct
53 Correct 3 ms 1740 KB Output is correct
54 Correct 2 ms 1740 KB Output is correct
55 Correct 2 ms 1740 KB Output is correct
56 Correct 2 ms 1732 KB Output is correct
57 Correct 2 ms 1736 KB Output is correct
58 Correct 2 ms 1740 KB Output is correct
59 Correct 2 ms 1740 KB Output is correct
60 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 8200 KB Output is correct
2 Correct 217 ms 8160 KB Output is correct
3 Correct 215 ms 8256 KB Output is correct
4 Correct 247 ms 8304 KB Output is correct
5 Correct 206 ms 8132 KB Output is correct
6 Correct 197 ms 8220 KB Output is correct
7 Correct 196 ms 8124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 6 ms 6476 KB Output is correct
6 Correct 8 ms 6732 KB Output is correct
7 Correct 21 ms 7220 KB Output is correct
8 Correct 34 ms 7704 KB Output is correct
9 Correct 55 ms 8240 KB Output is correct
10 Correct 30 ms 7560 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 26 ms 6812 KB Output is correct
13 Correct 22 ms 6884 KB Output is correct
14 Correct 22 ms 6860 KB Output is correct
15 Correct 110 ms 7644 KB Output is correct
16 Correct 85 ms 7548 KB Output is correct
17 Correct 56 ms 7764 KB Output is correct
18 Correct 204 ms 8224 KB Output is correct
19 Correct 155 ms 8160 KB Output is correct
20 Correct 113 ms 8244 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 456 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 584 KB Output is correct
41 Correct 1 ms 588 KB Output is correct
42 Correct 1 ms 588 KB Output is correct
43 Correct 1 ms 588 KB Output is correct
44 Correct 1 ms 584 KB Output is correct
45 Correct 1 ms 588 KB Output is correct
46 Correct 1 ms 588 KB Output is correct
47 Correct 1 ms 588 KB Output is correct
48 Correct 1 ms 588 KB Output is correct
49 Correct 1 ms 588 KB Output is correct
50 Correct 1 ms 588 KB Output is correct
51 Correct 1 ms 588 KB Output is correct
52 Correct 1 ms 588 KB Output is correct
53 Correct 1 ms 588 KB Output is correct
54 Correct 1 ms 588 KB Output is correct
55 Correct 1 ms 588 KB Output is correct
56 Correct 1 ms 584 KB Output is correct
57 Correct 1 ms 588 KB Output is correct
58 Correct 1 ms 588 KB Output is correct
59 Correct 1 ms 588 KB Output is correct
60 Correct 1 ms 588 KB Output is correct
61 Correct 1 ms 1604 KB Output is correct
62 Correct 2 ms 1484 KB Output is correct
63 Correct 2 ms 1612 KB Output is correct
64 Correct 1 ms 1604 KB Output is correct
65 Correct 2 ms 1736 KB Output is correct
66 Correct 2 ms 1612 KB Output is correct
67 Correct 2 ms 1740 KB Output is correct
68 Correct 3 ms 1740 KB Output is correct
69 Correct 2 ms 1860 KB Output is correct
70 Correct 2 ms 1732 KB Output is correct
71 Correct 3 ms 1864 KB Output is correct
72 Correct 3 ms 1852 KB Output is correct
73 Correct 3 ms 1740 KB Output is correct
74 Correct 2 ms 1740 KB Output is correct
75 Correct 2 ms 1740 KB Output is correct
76 Correct 2 ms 1732 KB Output is correct
77 Correct 2 ms 1736 KB Output is correct
78 Correct 2 ms 1740 KB Output is correct
79 Correct 2 ms 1740 KB Output is correct
80 Correct 2 ms 1740 KB Output is correct
81 Correct 213 ms 8200 KB Output is correct
82 Correct 217 ms 8160 KB Output is correct
83 Correct 215 ms 8256 KB Output is correct
84 Correct 247 ms 8304 KB Output is correct
85 Correct 206 ms 8132 KB Output is correct
86 Correct 197 ms 8220 KB Output is correct
87 Correct 196 ms 8124 KB Output is correct
88 Correct 10 ms 6484 KB Output is correct
89 Correct 8 ms 6460 KB Output is correct
90 Correct 22 ms 6660 KB Output is correct
91 Correct 22 ms 6724 KB Output is correct
92 Correct 66 ms 7140 KB Output is correct
93 Correct 61 ms 7256 KB Output is correct
94 Correct 123 ms 7664 KB Output is correct
95 Correct 143 ms 7748 KB Output is correct
96 Correct 163 ms 7996 KB Output is correct
97 Correct 181 ms 7924 KB Output is correct
98 Correct 116 ms 7588 KB Output is correct
99 Correct 135 ms 7640 KB Output is correct
100 Correct 116 ms 7548 KB Output is correct
101 Correct 118 ms 7616 KB Output is correct
102 Correct 122 ms 7600 KB Output is correct
103 Correct 105 ms 7540 KB Output is correct
104 Correct 124 ms 7672 KB Output is correct
105 Correct 143 ms 7660 KB Output is correct