답안 #666505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666505 2022-11-28T19:08:04 Z mychecksedad Boarding Passes (BOI22_passes) C++17
5 / 100
2 ms 1172 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
const int N = 1e5 + 100;

int n;
string s;
double dp[N];
vector<int> v[15];
void solve(){
    cin >> s; n = s.length();

    for(int i = 0; i < n; ++i) v[s[i]-'A'].push_back(i);

    if(v[0].size() == n){
        double k1 = n/2;
        double k2 = (n+1)/2;
        cout << (k1*(k1-1) + (k2)*(k2-1))/4.0;
        return;
    }

    vector<int> p = {0, 1, 2, 3, 4, 5, 6};

    double best = -1;


    do{
        double S = 0;
        vector<bool> vis(n);
        for(int i = 0; i < 7; ++i){
            int a = v[i].size();
            double best_k = -1;
            for(int k = 0; k <= a; ++k){
                double sum = 0;
                int po = 0, cur = 0;
                for(int j = 0; j <= k; ++j){
                    while(po < v[i][j]){
                        cur += vis[po];
                        po++;
                    }
                    sum += cur;
                }
                po = n - 1; cur = 0;
                for(int j = a - 1; j > k; --j){
                    while(po > v[i][j]){
                        cur += vis[po];
                        po--;
                    }
                    sum += cur;
                }
                for(double i = 2; i <= n; ++i) sum /= i;

                double k1 = a - k;
                double val = (k * (k-1) + k1*(k1-1))/4.0 + sum;
                best_k = best_k == -1 ? val : min(val, best_k);
            }
            for(int pos: v[i]) vis[pos] = 1;
            S += best_k;
        }
        
        best = best == -1 ? S : min(best, S);

    }while(next_permutation(all(p)));

    cout << best;
}



int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    setp();
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
    }
    return 0;
 
}

Compilation message

passes.cpp: In function 'void solve()':
passes.cpp:17:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     if(v[0].size() == n){
      |        ~~~~~~~~~~~~^~~~
passes.cpp: In function 'int main()':
passes.cpp:74:16: warning: unused variable 'aa' [-Wunused-variable]
   74 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 0 ms 212 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 0 ms 212 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 0 ms 212 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 0 ms 212 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Correct 1 ms 1172 KB found '772893586.0000000000', expected '772893586.0000000000', error '0.0000000000'
7 Correct 2 ms 1172 KB found '1100977812.5000000000', expected '1100977812.5000000000', error '0.0000000000'
8 Correct 2 ms 1172 KB found '1249950000.5000000000', expected '1249950000.5000000000', error '0.0000000000'
9 Correct 2 ms 1172 KB found '1249975000.0000000000', expected '1249975000.0000000000', error '0.0000000000'
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 0 ms 212 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 0 ms 212 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 0 ms 212 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 0 ms 212 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Correct 1 ms 1172 KB found '772893586.0000000000', expected '772893586.0000000000', error '0.0000000000'
7 Correct 2 ms 1172 KB found '1100977812.5000000000', expected '1100977812.5000000000', error '0.0000000000'
8 Correct 2 ms 1172 KB found '1249950000.5000000000', expected '1249950000.5000000000', error '0.0000000000'
9 Correct 2 ms 1172 KB found '1249975000.0000000000', expected '1249975000.0000000000', error '0.0000000000'
10 Runtime error 1 ms 468 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -