Submission #953657

# Submission time Handle Problem Language Result Execution time Memory
953657 2024-03-26T11:59:53 Z ifateen Boarding Passes (BOI22_passes) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 5, MAXG = 15;
map<char, int> m;
vector<vector<int>> pos;
int G;
double dp[1 << MAXG], PREF[MAXG][MAXG][MAXN], SUF[MAXN][MAXN][MAXG];
double compute(int i, int cnt, int mask) {
    double ret = 0;
    int rcnt = pos[i].size() - cnt;
    ret += cnt * (cnt - 1) * 0.25;
    ret += rcnt * (rcnt - 1) * 0.25;
    for (int j = 0; j < G; ++j) {
        if (mask & (1 << j)) ret += (cnt ? PREF[i][j][cnt - 1] : 0) + (rcnt ? SUF[i][j][rcnt - 1] : 0);
    }
    return ret;
}
signed main() {
    string s;
    cin >> s;
    vector<int> v(s.length());
    int cnt = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (m.find(s[i]) != m.end()) v[i] = m[s[i]];
        else v[i] = m[s[i]] = cnt++;
    }
    G = *max_element(begin(v), end(v)) + 1;
    pos.resize(G);
    int n = s.length();
    for (int i = 0; i < n; ++i) pos[v[i]].push_back(i);
    dp[0] = 0;
    for (int i = 0; i < G; ++i) {
        for (int j = 0; j < G; ++j) {
            if (i == j) continue;
            int ptr = 0, cant = 0;
            for (int k = 0; k < pos[i].size(); ++k) {
                while (ptr < pos[i][k]) cant += v[ptr++] == j;
                PREF[i][j][k] = cant;
                if (k) PREF[i][j][k] += PREF[i][j][k - 1];
            }
            ptr = n - 1, cant = 0;
            for (int k = 0; k < pos[i].size(); ++k) {
                int idx = pos[i].size() - k - 1;
                while (ptr > pos[i][idx]) cant += v[ptr--] == j;
                SUF[i][j][k] = cant;
                if (k) SUF[i][j][k] += SUF[i][j][k - 1];
            }
        }
    }
    for (int mask = 1; mask < (1 << G); mask++) {
        dp[mask] = 1e18;
        for (int i = 0; i < G; i++) {
            if (!(mask & (1 << i))) continue;
            double EV = compute(i, pos[i].size(), mask);
            int l = 0, r = pos[i].size() - 1;
            while (l <= r) {
                int mid = (l + r) >> 1;
                if (compute(i, mid, mask) <= compute(i, mid + 1, mask)) EV = min(EV, compute(i, mid, mask)), r = mid - 1;
                else l = mid + 1;
            }
            dp[mask] = min(dp[mask], EV + dp[mask ^ (1 << i)]);
        }
    }
    cout << fixed << setprecision(8) << dp[(1 << G) - 1];
}

Compilation message

passes.cpp: In function 'int main()':
passes.cpp:24:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < s.length(); ++i) {
      |                     ~~^~~~~~~~~~~~
passes.cpp:37: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]
   37 |             for (int k = 0; k < pos[i].size(); ++k) {
      |                             ~~^~~~~~~~~~~~~~~
passes.cpp:43: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]
   43 |             for (int k = 0; k < pos[i].size(); ++k) {
      |                             ~~^~~~~~~~~~~~~~~
/tmp/ccWTOa8s.o: in function `compute(long long, long long, long long)':
passes.cpp:(.text+0xa): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text+0x43): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text+0x95): relocation truncated to fit: R_X86_64_PC32 against symbol `PREF' defined in .bss section in /tmp/ccWTOa8s.o
/tmp/ccWTOa8s.o: in function `main':
passes.cpp:(.text.startup+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
passes.cpp:(.text.startup+0xed): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x102): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x18b): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x1f3): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x207): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x20e): relocation truncated to fit: R_X86_64_PC32 against symbol `pos' defined in .bss section in /tmp/ccWTOa8s.o
passes.cpp:(.text.startup+0x21f): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status