Submission #638708

# Submission time Handle Problem Language Result Execution time Memory
638708 2022-09-07T04:54:12 Z jamezzz Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
1351 ms 1004540 KB
#include <bits/stdc++.h>
using namespace std;

#define pf printf
#define sf scanf
typedef long long ll;
typedef pair<int,int> ii;

#define maxn 505
#define INF 1023456789

int n,k,a[maxn],b[maxn];
vector<ii> v;
double memo[maxn+5][maxn+5][maxn+5];

double dp(int pos,int ppl,int vote){
	if(pos==n){
		if(vote>=k)return 0;
		else return INF;
	}
	if(memo[pos][ppl][vote]>=0)return memo[pos][ppl][vote];
	double ans=INF;
	//case 1: dont take
	ans=min(ans,dp(pos+1,ppl,vote));
	//case 2: just get vote
	ans=min(ans,dp(pos+1,ppl,vote+1)+(double)a[pos]/(ppl+1));
	//case 3: get new person
	if(b[pos]!=INF)ans=min(ans,dp(pos+1,ppl+1,vote+1)+(double)b[pos]/(ppl+1));
	//pf("%d %d %d: %f\n",pos,ppl,vote,ans);
	return memo[pos][ppl][vote]=ans;
}

int main(){
	sf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		int x,y;
		sf("%d%d",&x,&y);
		if(y==-1)y=INF;
		v.push_back({y,x});
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;++i){
		tie(b[i],a[i])=v[i];
	}
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n;++j){
			for(int l=0;l<=n;++l){
				memo[i][j][l]=-1;
			}
		}
	}
	pf("%f\n",dp(0,0,0));
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  sf("%d%d",&n,&k);
      |    ^
Main.cpp:37:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   sf("%d%d",&x,&y);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 442 ms 1004332 KB Output is correct
6 Correct 407 ms 1004364 KB Output is correct
7 Correct 400 ms 1004328 KB Output is correct
8 Correct 390 ms 1004312 KB Output is correct
9 Correct 393 ms 1004432 KB Output is correct
10 Correct 405 ms 1004256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 442 ms 1004332 KB Output is correct
6 Correct 407 ms 1004364 KB Output is correct
7 Correct 400 ms 1004328 KB Output is correct
8 Correct 390 ms 1004312 KB Output is correct
9 Correct 393 ms 1004432 KB Output is correct
10 Correct 405 ms 1004256 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1326 ms 1004432 KB Output is correct
13 Correct 986 ms 1004540 KB Output is correct
14 Correct 558 ms 1004372 KB Output is correct
15 Correct 1316 ms 1004392 KB Output is correct
16 Correct 1143 ms 1004368 KB Output is correct
17 Correct 562 ms 1004384 KB Output is correct
18 Correct 1274 ms 1004320 KB Output is correct
19 Correct 1089 ms 1004452 KB Output is correct
20 Correct 570 ms 1004320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 568 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 572 KB Output is correct
6 Correct 1 ms 576 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 568 KB Output is correct
9 Incorrect 1 ms 596 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 568 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 572 KB Output is correct
6 Correct 1 ms 576 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 568 KB Output is correct
9 Incorrect 1 ms 596 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 568 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 572 KB Output is correct
6 Correct 1 ms 576 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 568 KB Output is correct
9 Incorrect 1 ms 596 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1351 ms 1004372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 442 ms 1004332 KB Output is correct
6 Correct 407 ms 1004364 KB Output is correct
7 Correct 400 ms 1004328 KB Output is correct
8 Correct 390 ms 1004312 KB Output is correct
9 Correct 393 ms 1004432 KB Output is correct
10 Correct 405 ms 1004256 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1326 ms 1004432 KB Output is correct
13 Correct 986 ms 1004540 KB Output is correct
14 Correct 558 ms 1004372 KB Output is correct
15 Correct 1316 ms 1004392 KB Output is correct
16 Correct 1143 ms 1004368 KB Output is correct
17 Correct 562 ms 1004384 KB Output is correct
18 Correct 1274 ms 1004320 KB Output is correct
19 Correct 1089 ms 1004452 KB Output is correct
20 Correct 570 ms 1004320 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 568 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 572 KB Output is correct
26 Correct 1 ms 576 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 0 ms 568 KB Output is correct
29 Incorrect 1 ms 596 KB Output isn't correct
30 Halted 0 ms 0 KB -