# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1098975 | crafticat | Boarding Passes (BOI22_passes) | C++17 | 3 ms | 2324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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()) {
int orgLEF = points.order_of_key(x[i]);
int orgRIG = points.size() - orgLEF;
double lef = orgLEF + (i / 2.0);
double rig = orgRIG + (x.size() - i - 1) / 2.0;
expected += min(lef, rig);
}
return expected;
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |