# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
514797 | Theo830 | Cheerleaders (info1cup20_cheerleaders) | C++17 | 2110 ms | 765184 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
template <typename T> struct Bit{
int N;
vector<T>bit;
void build(ll n){
N = n+5;
f(i,0,N){
bit.pb(0);
}
}
void upd(ll k,T x){
while(k < N){
bit[k] += x;
k += k & -k;
}
}
T query(ll k){
T ans = 0;
while(k >= 1){
ans += bit[k];
k -= k & -k;
}
return ans;
}
};
ll n;
vll arr;
ll c(vll a){
ll ans = 0;
Bit<ll>b;
b.build(a.size() + 5);
f(j,0,(ll)a.size()){
ans += j - b.query(a[j]+1);
b.upd(a[j]+1,1);
}
return ans;
}
vll ena(vll a){
vll ans;
ll m = a.size() / 2;
f(i,m,a.size()){
ans.pb(a[i]);
}
f(i,0,m){
ans.pb(a[i]);
}
return ans;
}
vll dio(vll a){
vll ans;
f(i,0,a.size()){
ans.pb(a[i]);
i++;
}
f(i,1,a.size()){
ans.pb(a[i]);
i++;
}
return ans;
}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
n = (1LL<<n);
f(i,0,n){
ll a;
cin>>a;
arr.pb(a);
}
map<vll,bool>v;
queue<vll>q;
q.push(arr);
v[arr] = 1;
ll ans = 1e18;
while(!q.empty()){
vll f = q.front();
q.pop();
ans = min(ans,c(f));
vll A = ena(f);
if(!v[A]){
v[A] = 1;
q.push(A);
}
A = dio(f);
if(!v[A]){
v[A] = 1;
q.push(A);
}
}
cout<<ans<<"\n";
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |