# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101210 | 2024-10-15T18:38:07 Z | andrei_iorgulescu | Boarding Passes (BOI22_passes) | C++14 | 3 ms | 23004 KB |
#include <bits/stdc++.h> using namespace std; #define int long long using ld = long double; ld inf = 1e12; int n, g; char a[100005]; int v[100005]; string ssss; vector<int> pos[20]; int p[20][20][100005], s[20][20][100005]; int sp[100005]; ld dp[50005]; ld f(int b, int mask, int x) { ld ans = dp[mask - (1 << b)]; ld xxx = x; ans += ((xxx * (xxx - 1)) / 4.0d); ld xx = pos[b].size() - x; ans += ((xx * (xx - 1)) / 4.0d); //cout << b << ' ' << mask << ' ' << x << ' '; for (int b1 = 0; b1 < g; b1++) { if (b1 != b and ((1 << b1) & mask)) { ans += p[b][b1][x]; ans += s[b][b1][pos[b].size() - x]; } } //cout << ans << endl; return ans; } signed main() { cin >> ssss; n = ssss.size(); for (int i = 1; i <= n; i++) a[i] = ssss[i - 1]; for (int i = 1; i <= n; i++) v[i] = a[i] - 'A', g = max(g, v[i] + 1); for (int i = 1; i <= n; i++) pos[v[i]].push_back(i); for (int i = 0; i < g; i++) { for (int j = 0; j < g; j++) { if (i == j) continue; for (int q = 1; q <= n; q++) { sp[q] = sp[q - 1]; if (v[q] == j) sp[q]++; } for (int q = 0; q <= pos[i].size(); q++) { int sm = 0; if (q > 1) sm = p[i][j][q - 1]; if (q != 0) sm += sp[pos[i][q - 1]]; p[i][j][q] = sm; } for (int q = 0; q <= pos[i].size(); q++) { int sm = 0; if (q > 1) sm = s[i][j][q - 1]; if (q != 0) sm += (sp[n] - sp[pos[i][pos[i].size() - q]]); s[i][j][q] = sm; } } } for (int mask = 1; mask < (1 << g); mask++) { dp[mask] = inf; for (int b = 0; b < g; b++) { if (mask & (1 << b)) { int st = 0, pas = 1 << 16; while (pas != 0) { if (st + pas + 1 <= pos[b].size() and f(b, mask, st + pas) <= f(b, mask, st + pas + 1)) st += pas; pas /= 2; } for (int dlt = -2; dlt <= 2; dlt++) if (st + dlt >= 0 and st + dlt <= pos[b].size()) dp[mask] = min(dp[mask], f(b, mask, st + dlt)); } } } cout << setprecision(5) << fixed; cout << dp[(1 << g) - 1]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2524 KB | 1st numbers differ - expected: '100800.5000000000', found: '200481.5000000000', error = '0.9888939043' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23004 KB | found '1.0000000000', expected '1.0000000000', error '0.0000000000' |
2 | Incorrect | 3 ms | 22868 KB | 1st numbers differ - expected: '1225.0000000000', found: '2329.5000000000', error = '0.9016326531' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23004 KB | found '1.0000000000', expected '1.0000000000', error '0.0000000000' |
2 | Incorrect | 3 ms | 22868 KB | 1st numbers differ - expected: '1225.0000000000', found: '2329.5000000000', error = '0.9016326531' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2524 KB | 1st numbers differ - expected: '100800.5000000000', found: '200481.5000000000', error = '0.9888939043' |
2 | Halted | 0 ms | 0 KB | - |