제출 #514797

#제출 시각아이디문제언어결과실행 시간메모리
514797Theo830Cheerleaders (info1cup20_cheerleaders)C++17
13 / 100
2110 ms765184 KiB
#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) 메시지

cheerleaders.cpp: In function 'std::vector<long long int> ena(std::vector<long long int>)':
cheerleaders.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
   64 |     f(i,m,a.size()){
      |       ~~~~~~~~~~~~               
cheerleaders.cpp:64:5: note: in expansion of macro 'f'
   64 |     f(i,m,a.size()){
      |     ^
cheerleaders.cpp: In function 'std::vector<long long int> dio(std::vector<long long int>)':
cheerleaders.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
   74 |     f(i,0,a.size()){
      |       ~~~~~~~~~~~~               
cheerleaders.cpp:74:5: note: in expansion of macro 'f'
   74 |     f(i,0,a.size()){
      |     ^
cheerleaders.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
   78 |     f(i,1,a.size()){
      |       ~~~~~~~~~~~~               
cheerleaders.cpp:78:5: note: in expansion of macro 'f'
   78 |     f(i,1,a.size()){
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...