Submission #578165

# Submission time Handle Problem Language Result Execution time Memory
578165 2022-06-16T06:33:00 Z 8e7 Boarding Passes (BOI22_passes) C++17
60 / 100
705 ms 2192 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...); }
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define maxc 10
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
ll dp[1<<maxc];
int pref[maxn], suf[maxn], col[maxn];
vector<int> pos[maxc];
int main() {
	io
	ll n;
	string s;
	cin >> s;
	n = s.size();
	/*
	ll p = n / 2;
	cout << fixed << setprecision(5) << (double)(p * (p - 1) + (n-p) * (n-p - 1)) / 4 << "\n";
	return 0;
	*/
	for (int i = 0;i < n;i++) {
		int c = s[i] - 'A';
		pos[c].push_back(i);	
		col[i] = c;
	}
	for (int i = 0;i < (1<<maxc);i++) dp[i] = inf;
	dp[0] = 0;
	for (int i = 0;i < (1<<maxc);i++) {
		for (int j = 0;j < n;j++) {
			pref[j] = suf[j] = (i >> col[j])&1;
			pref[j] += j ? pref[j-1] : 0;
		}
		for (int j = n - 2;j >= 0;j--)suf[j] += suf[j+1];
		for (int j = 0;j < maxc;j++) {
			if (!((i >> j) & 1)) {
				ll cur = 0, pc = 0, sc = 0;		
				for (int k:pos[j]) {
					cur += pref[k];
					pc++;
				}
				int to = i + (1<<j);
				dp[to] = min(dp[to], dp[i] + cur*4 + pc * (pc-1));
				for (int k = (int)pos[j].size() - 1;k >= 0;k--) {
					sc++;
					pc--;
					cur += suf[pos[j][k]] - pref[pos[j][k]];
					dp[to] = min(dp[to], dp[i] + cur*4 + pc * (pc-1) + sc * (sc-1));
				}
			}
		}
	}
	ll ans = dp[(1<<maxc) - 1];
	ll a0 = ans / 4;
	cout << a0;
	if (ans % 4 == 1) {
		cout << ".25\n";
	} else if (ans % 4 == 2) {
		cout << ".5\n";
	} else if (ans % 4 == 3) {
		cout << ".75\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 8 ms 340 KB Output is correct
6 Correct 519 ms 1808 KB Output is correct
7 Correct 653 ms 2064 KB Output is correct
8 Correct 705 ms 2192 KB Output is correct
9 Correct 693 ms 2192 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 340 KB Output is correct
4 Correct 2 ms 340 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 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 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 340 KB Output is correct
4 Correct 2 ms 340 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 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 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 1 ms 212 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 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 388 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 70 ms 564 KB Output is correct
36 Correct 70 ms 468 KB Output is correct
37 Correct 76 ms 468 KB Output is correct
38 Correct 71 ms 504 KB Output is correct
39 Correct 67 ms 576 KB Output is correct
40 Correct 68 ms 504 KB Output is correct
41 Correct 71 ms 532 KB Output is correct
42 Correct 71 ms 524 KB Output is correct
43 Correct 77 ms 532 KB Output is correct
44 Correct 68 ms 468 KB Output is correct
45 Correct 67 ms 468 KB Output is correct
46 Correct 68 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 8 ms 340 KB Output is correct
6 Correct 519 ms 1808 KB Output is correct
7 Correct 653 ms 2064 KB Output is correct
8 Correct 705 ms 2192 KB Output is correct
9 Correct 693 ms 2192 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 212 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 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 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 388 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 70 ms 564 KB Output is correct
45 Correct 70 ms 468 KB Output is correct
46 Correct 76 ms 468 KB Output is correct
47 Correct 71 ms 504 KB Output is correct
48 Correct 67 ms 576 KB Output is correct
49 Correct 68 ms 504 KB Output is correct
50 Correct 71 ms 532 KB Output is correct
51 Correct 71 ms 524 KB Output is correct
52 Correct 77 ms 532 KB Output is correct
53 Correct 68 ms 468 KB Output is correct
54 Correct 67 ms 468 KB Output is correct
55 Correct 68 ms 528 KB Output is correct
56 Runtime error 1 ms 468 KB Execution killed with signal 11
57 Halted 0 ms 0 KB -