Submission #582102

# Submission time Handle Problem Language Result Execution time Memory
582102 2022-06-23T11:28:00 Z amunduzbaev Boarding Passes (BOI22_passes) C++17
60 / 100
2000 ms 1516 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
#define int ll

const int G = 15;
int dp[1 << G]; 

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	string s; cin>>s;
	int n = s.size(), g = 0;
	for(int i=0;i<n;i++){
		g = max(g, (ll)s[i] - 'A' + 1);
	}
	
	memset(dp, 63, sizeof dp);
	dp[0] = 0;
	int pref[n + 5];
	for(int mask=0;mask < (1 << g);mask++){
		for(int j=0;j<g;j++){
			if(mask >> j & 1) continue;
			memset(pref, 0, sizeof pref);
			int cnt = 0;
			for(int k=0;k<n;k++){
				if(k) pref[k] += pref[k-1];
				if(s[k] - 'A' == j){
					pref[k] += cnt;
					cnt++;
				}
				if(mask >> (s[k] - 'A') & 1) cnt += 2;
			}
			
			int suff = 0, res = pref[n - 1]; cnt = 0;
			for(int i=n-1;~i;i--){
				if(s[i] - 'A' == j){
					suff += cnt, cnt++;
				}
				res = min(res, suff + (i ? pref[i-1] : 0));
				if(mask >> (s[i] - 'A') & 1) cnt += 2;
			}
			
			dp[mask | (1 << j)] = min(dp[mask | (1 << j)], dp[mask] + res);
		}
	}
	
	int res = dp[(1 << g) - 1];
	cout<<res/2;
	if(res&1) cout<<".5";
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 1388 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 2 ms 1492 KB Output is correct
9 Correct 2 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 50 ms 596 KB Output is correct
36 Correct 52 ms 664 KB Output is correct
37 Correct 282 ms 668 KB Output is correct
38 Correct 236 ms 660 KB Output is correct
39 Correct 234 ms 656 KB Output is correct
40 Correct 246 ms 652 KB Output is correct
41 Correct 264 ms 656 KB Output is correct
42 Correct 247 ms 656 KB Output is correct
43 Correct 254 ms 656 KB Output is correct
44 Correct 290 ms 652 KB Output is correct
45 Correct 244 ms 648 KB Output is correct
46 Correct 250 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 1388 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 2 ms 1492 KB Output is correct
9 Correct 2 ms 1516 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 50 ms 596 KB Output is correct
45 Correct 52 ms 664 KB Output is correct
46 Correct 282 ms 668 KB Output is correct
47 Correct 236 ms 660 KB Output is correct
48 Correct 234 ms 656 KB Output is correct
49 Correct 246 ms 652 KB Output is correct
50 Correct 264 ms 656 KB Output is correct
51 Correct 247 ms 656 KB Output is correct
52 Correct 254 ms 656 KB Output is correct
53 Correct 290 ms 652 KB Output is correct
54 Correct 244 ms 648 KB Output is correct
55 Correct 250 ms 656 KB Output is correct
56 Correct 21 ms 468 KB Output is correct
57 Correct 42 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 0 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 2 ms 1364 KB Output is correct
64 Correct 2 ms 1492 KB Output is correct
65 Correct 2 ms 1464 KB Output is correct
66 Correct 2 ms 1492 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 0 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 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 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 0 ms 468 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 1 ms 468 KB Output is correct
84 Correct 46 ms 596 KB Output is correct
85 Correct 55 ms 648 KB Output is correct
86 Correct 288 ms 596 KB Output is correct
87 Correct 221 ms 652 KB Output is correct
88 Correct 251 ms 656 KB Output is correct
89 Correct 223 ms 652 KB Output is correct
90 Correct 247 ms 652 KB Output is correct
91 Correct 246 ms 596 KB Output is correct
92 Correct 249 ms 668 KB Output is correct
93 Correct 251 ms 648 KB Output is correct
94 Correct 244 ms 652 KB Output is correct
95 Correct 270 ms 716 KB Output is correct
96 Execution timed out 2080 ms 1476 KB Time limit exceeded
97 Halted 0 ms 0 KB -