답안 #1098968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098968 2024-10-10T11:42:49 Z crafticat Boarding Passes (BOI22_passes) C++17
5 / 100
55 ms 6888 KB
#include <bits/stdc++.h>

#include <utility>

using ll = long long;
using namespace std;
#define F0R(i, n) for (ll i= 0; i < n;i++)
template<typename T>
using V = vector<T>;
using vi = V<ll>;
using vvi = V<vi>;
#define pb push_back
using pi = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define f first
#define s second

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <class T>
using Tree =
        tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

double add(vi x, Tree<int> &points) {
    long double expected = 0;
    F0R(i, x.size()) {
        points.insert(x[i]);
    }
    F0R(i, x.size()) {
        int lef = points.order_of_key(x[i]);
        int rig = points.size() - lef - 1;
        if (lef == 450) {
            int stop = 25;
        }

        expected += min(lef, rig);
    }

    return expected / 2.0;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    string str; cin >> str;
    set<int> ind;
    vvi groups(26);
    F0R(i, str.size()) {
        int id = str[i] - 'A';
        groups[id].pb(i);
        ind.insert(id);
    }

    vi perm;
    for (auto x : ind)
        perm.pb(x);

    double ans = 1e18;
    do {
        Tree<int> points;
        double expected = 0;
        for (auto x : perm) {
            expected += add(groups[x], points);
        }
        ans = min(ans, expected);
    } while (std::next_permutation(all(perm)));

    cout << fixed << ans;
    return 0;
}

Compilation message

passes.cpp: In function 'double add(vi, Tree<int>&)':
passes.cpp:7:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define F0R(i, n) for (ll i= 0; i < n;i++)
......
   27 |     F0R(i, x.size()) {
      |         ~~~~~~~~~~~                
passes.cpp:27:5: note: in expansion of macro 'F0R'
   27 |     F0R(i, x.size()) {
      |     ^~~
passes.cpp:7:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define F0R(i, n) for (ll i= 0; i < n;i++)
......
   30 |     F0R(i, x.size()) {
      |         ~~~~~~~~~~~                
passes.cpp:30:5: note: in expansion of macro 'F0R'
   30 |     F0R(i, x.size()) {
      |     ^~~
passes.cpp:34:17: warning: unused variable 'stop' [-Wunused-variable]
   34 |             int stop = 25;
      |                 ^~~~
passes.cpp: In function 'int main()':
passes.cpp:7:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define F0R(i, n) for (ll i= 0; i < n;i++)
......
   49 |     F0R(i, str.size()) {
      |         ~~~~~~~~~~~~~              
passes.cpp:49:5: note: in expansion of macro 'F0R'
   49 |     F0R(i, str.size()) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 0 ms 348 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 0 ms 456 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 1 ms 348 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 1 ms 348 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Correct 37 ms 5332 KB found '772893586.0000000000', expected '772893586.0000000000', error '0.0000000000'
7 Correct 46 ms 6412 KB found '1100977812.5000000000', expected '1100977812.5000000000', error '0.0000000000'
8 Correct 55 ms 6888 KB found '1249950000.5000000000', expected '1249950000.5000000000', error '0.0000000000'
9 Correct 51 ms 6664 KB found '1249975000.0000000000', expected '1249975000.0000000000', error '0.0000000000'
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
2 Correct 0 ms 456 KB found '1225.0000000000', expected '1225.0000000000', error '0.0000000000'
3 Incorrect 37 ms 348 KB 1st numbers differ - expected: '1023.0000000000', found: '597.5000000000', error = '0.4159335288'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
2 Correct 0 ms 456 KB found '1225.0000000000', expected '1225.0000000000', error '0.0000000000'
3 Incorrect 37 ms 348 KB 1st numbers differ - expected: '1023.0000000000', found: '597.5000000000', error = '0.4159335288'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 0 ms 348 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 0 ms 456 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 1 ms 348 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 1 ms 348 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Correct 37 ms 5332 KB found '772893586.0000000000', expected '772893586.0000000000', error '0.0000000000'
7 Correct 46 ms 6412 KB found '1100977812.5000000000', expected '1100977812.5000000000', error '0.0000000000'
8 Correct 55 ms 6888 KB found '1249950000.5000000000', expected '1249950000.5000000000', error '0.0000000000'
9 Correct 51 ms 6664 KB found '1249975000.0000000000', expected '1249975000.0000000000', error '0.0000000000'
10 Correct 1 ms 348 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
11 Correct 0 ms 456 KB found '1225.0000000000', expected '1225.0000000000', error '0.0000000000'
12 Incorrect 37 ms 348 KB 1st numbers differ - expected: '1023.0000000000', found: '597.5000000000', error = '0.4159335288'
13 Halted 0 ms 0 KB -