답안 #703929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703929 2023-03-01T03:12:19 Z niter Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
142 ms 1356 KB
#include<stdio.h>
#include<algorithm>
#define R register int
#define D double
#define I inline
#define INF 999999999
I void Min(D&x,const D y){
	if(x>y){
		x=y;
	}
}
struct State{
	int ValA,ValB;
	I void Read(){
		scanf("%d%d",&ValA,&ValB);
		if(ValB==-1){
			ValB=INF;
		}
	}
	I friend bool operator<(State A,State B){
		return A.ValB<B.ValB;
	}
}s[501];
D f[501],g[501];
int suf[502][501];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(R i=1;i<=n;i++){
		s[i].Read();
	}
	std::sort(s+1,s+n+1);
	for(R i=n;i!=0;i--){
		for(R j=n-i+1;j!=0;j--){
			suf[i][j]=suf[i+1][j-1]+s[i].ValA;
		}
		for(R j=1;j<=n-i;j++){
			if(suf[i+1][j]<suf[i][j]){
				suf[i][j]=suf[i+1][j];
			}
		}
	}
	D ans=suf[1][m];
	for(R i=1;i<=m;i++){
		D inv=1/(1.0+i);
		f[0]=0;
		for(R j=1;j<=n&&j<=m;j++){
			for(R k=0;k<=j&&k<=i;k++){
				g[k]=INF;
			}
			for(R k=0;k!=j&&k<=i;k++){
				Min(g[k],f[k]+inv*s[j].ValA);
				Min(g[k+1],f[k]+s[j].ValB/(1.0+k));
			}
			for(R k=0;k<=j&&k<=i;k++){
				f[k]=g[k];
			}
			if(j>=i){
				Min(ans,f[i]+inv*suf[j+1][m-j]);
			}
		}
	}
	printf("%.9lf",ans);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d %d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
Main.cpp: In member function 'void State::Read()':
Main.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d%d",&ValA,&ValB);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 3 ms 1184 KB Output is correct
7 Correct 17 ms 1280 KB Output is correct
8 Correct 53 ms 1264 KB Output is correct
9 Correct 119 ms 1260 KB Output is correct
10 Correct 42 ms 1256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 3 ms 1184 KB Output is correct
7 Correct 17 ms 1280 KB Output is correct
8 Correct 53 ms 1264 KB Output is correct
9 Correct 119 ms 1260 KB Output is correct
10 Correct 42 ms 1256 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1236 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 48 ms 1260 KB Output is correct
16 Correct 48 ms 1236 KB Output is correct
17 Correct 50 ms 1356 KB Output is correct
18 Correct 131 ms 1260 KB Output is correct
19 Correct 132 ms 1236 KB Output is correct
20 Correct 131 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 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 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 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 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 292 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 288 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 292 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 288 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 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 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 292 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 288 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 292 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 288 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 424 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 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 416 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 2 ms 480 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 424 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 135 ms 1236 KB Output is correct
2 Correct 135 ms 1264 KB Output is correct
3 Correct 142 ms 1264 KB Output is correct
4 Correct 140 ms 1256 KB Output is correct
5 Correct 133 ms 1260 KB Output is correct
6 Correct 137 ms 1256 KB Output is correct
7 Correct 136 ms 1300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 3 ms 1184 KB Output is correct
7 Correct 17 ms 1280 KB Output is correct
8 Correct 53 ms 1264 KB Output is correct
9 Correct 119 ms 1260 KB Output is correct
10 Correct 42 ms 1256 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1236 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 48 ms 1260 KB Output is correct
16 Correct 48 ms 1236 KB Output is correct
17 Correct 50 ms 1356 KB Output is correct
18 Correct 131 ms 1260 KB Output is correct
19 Correct 132 ms 1236 KB Output is correct
20 Correct 131 ms 1260 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 292 KB Output is correct
23 Correct 0 ms 288 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 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 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 292 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 292 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 288 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 0 ms 292 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 288 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 0 ms 468 KB Output is correct
62 Correct 1 ms 424 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 468 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 416 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 2 ms 468 KB Output is correct
72 Correct 2 ms 480 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 468 KB Output is correct
78 Correct 1 ms 424 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 135 ms 1236 KB Output is correct
82 Correct 135 ms 1264 KB Output is correct
83 Correct 142 ms 1264 KB Output is correct
84 Correct 140 ms 1256 KB Output is correct
85 Correct 133 ms 1260 KB Output is correct
86 Correct 137 ms 1256 KB Output is correct
87 Correct 136 ms 1300 KB Output is correct
88 Correct 2 ms 1192 KB Output is correct
89 Correct 1 ms 1236 KB Output is correct
90 Correct 4 ms 1184 KB Output is correct
91 Correct 4 ms 1236 KB Output is correct
92 Correct 21 ms 1276 KB Output is correct
93 Correct 19 ms 1276 KB Output is correct
94 Correct 60 ms 1236 KB Output is correct
95 Correct 59 ms 1256 KB Output is correct
96 Correct 99 ms 1236 KB Output is correct
97 Correct 104 ms 1256 KB Output is correct
98 Correct 49 ms 1236 KB Output is correct
99 Correct 49 ms 1260 KB Output is correct
100 Correct 50 ms 1264 KB Output is correct
101 Correct 51 ms 1260 KB Output is correct
102 Correct 49 ms 1236 KB Output is correct
103 Correct 50 ms 1260 KB Output is correct
104 Correct 56 ms 1236 KB Output is correct
105 Correct 48 ms 1280 KB Output is correct