Submission #1101214

#TimeUsernameProblemLanguageResultExecution timeMemory
1101214andrei_iorgulescuBoarding Passes (BOI22_passes)C++14
100 / 100
363 ms107116 KiB
#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 (stderr)

passes.cpp: In function 'int main()':
passes.cpp:63:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int q = 0; q <= pos[i].size(); q++)
      |                             ~~^~~~~~~~~~~~~~~~
passes.cpp:72:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for (int q = 0; q <= pos[i].size(); q++)
      |                             ~~^~~~~~~~~~~~~~~~
passes.cpp:93:38: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                     if (st + pas + 1 <= pos[b].size() and f(b, mask, st + pas) >= f(b, mask, st + pas + 1))
      |                         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
passes.cpp:98:52: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |                     if (st + dlt >= 0 and st + dlt <= pos[b].size())
      |                                           ~~~~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...