結果
問題 | No.2304 Distinct Elements |
ユーザー | Taiki0715 |
提出日時 | 2023-11-14 18:21:07 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 68 ms / 3,000 ms |
コード長 | 4,188 bytes |
コンパイル時間 | 7,120 ms |
コンパイル使用メモリ | 180,480 KB |
実行使用メモリ | 7,036 KB |
最終ジャッジ日時 | 2024-09-26 03:37:47 |
合計ジャッジ時間 | 10,430 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 44 ms
6,908 KB |
testcase_05 | AC | 42 ms
6,916 KB |
testcase_06 | AC | 41 ms
7,036 KB |
testcase_07 | AC | 44 ms
6,912 KB |
testcase_08 | AC | 44 ms
6,908 KB |
testcase_09 | AC | 65 ms
6,908 KB |
testcase_10 | AC | 64 ms
6,912 KB |
testcase_11 | AC | 65 ms
6,908 KB |
testcase_12 | AC | 64 ms
6,912 KB |
testcase_13 | AC | 68 ms
6,912 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 37 ms
6,512 KB |
testcase_30 | AC | 5 ms
5,376 KB |
testcase_31 | AC | 30 ms
5,376 KB |
testcase_32 | AC | 50 ms
6,576 KB |
testcase_33 | AC | 6 ms
5,376 KB |
testcase_34 | AC | 55 ms
6,604 KB |
testcase_35 | AC | 61 ms
6,760 KB |
testcase_36 | AC | 5 ms
5,376 KB |
testcase_37 | AC | 16 ms
5,376 KB |
testcase_38 | AC | 47 ms
6,892 KB |
testcase_39 | AC | 48 ms
6,916 KB |
testcase_40 | AC | 27 ms
6,384 KB |
testcase_41 | AC | 15 ms
5,376 KB |
testcase_42 | AC | 36 ms
6,912 KB |
testcase_43 | AC | 48 ms
6,912 KB |
testcase_44 | AC | 47 ms
6,596 KB |
testcase_45 | AC | 36 ms
5,376 KB |
testcase_46 | AC | 28 ms
5,376 KB |
testcase_47 | AC | 1 ms
5,376 KB |
testcase_48 | AC | 2 ms
5,376 KB |
testcase_49 | AC | 43 ms
6,912 KB |
testcase_50 | AC | 46 ms
6,912 KB |
testcase_51 | AC | 46 ms
6,912 KB |
testcase_52 | AC | 41 ms
6,912 KB |
testcase_53 | AC | 35 ms
6,916 KB |
testcase_54 | AC | 38 ms
6,912 KB |
testcase_55 | AC | 38 ms
6,836 KB |
testcase_56 | AC | 36 ms
6,912 KB |
testcase_57 | AC | 46 ms
6,876 KB |
testcase_58 | AC | 45 ms
7,036 KB |
testcase_59 | AC | 39 ms
6,912 KB |
testcase_60 | AC | 2 ms
5,376 KB |
testcase_61 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast<void>(0) #define debugg(...) static_cast<void>(0) template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;} #endif using ll=long long; using ull=unsigned long long; using P=pair<ll,ll>; template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>; template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);} template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;} template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;} template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;} template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;} template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;} template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcount(x) ll myceil(ll a,ll b){return (a+b-1)/b;} template<typename T,size_t n,size_t id=0> auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init)); else return init; } void SOLVE(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL clock_t start=clock(); #endif int testcase=1; //cin>>testcase; for(int i=0;i<testcase;i++){ SOLVE(); } #ifdef LOCAL cerr<<"time:"; cerr<<(clock()-start)/1000; cerr<<"ms\n"; #endif } template<typename T> struct slope_trick{ private: priority_queue<T>left; minque<T>right; T mn; T left_shift,right_shift; void left_push(T a){left.push(a-left_shift);} T left_top()const{return left.top()+left_shift;} void right_push(T a){right.push(a-right_shift);} T right_top()const{return right.top()+right_shift;} //f(x)+=max(0,x-a) void add_right(T a){ if(left.empty()||left_top()<a)right_push(a); else{ mn+=max<T>(0,left_top()-a); left_push(a); right_push(left_top()); left.pop(); } } //f(x)+=max(0,a-x) void add_left(T a){ if(right.empty()||right_top()>a)left_push(a); else{ mn+=max<T>(0,a-right_top()); right_push(a); left_push(right_top()); right.pop(); } } public: //f(x)=0 slope_trick():mn(0),left_shift(0),right_shift(0),left(),right(){} //f(x)+=|x-a| void add(T a){ add_left(a); add_right(a); } T min()const{return mn;} //f(x)=min[x-b<=y<=x-a](f(y)) void xshift(T a,T b){ assert(a<=b); left_shift+=a; right_shift+=b; } //f(x)=f(x-a) void xshift(T a){ left_shift+=a; right_shift+=a; } //f(x)+=a void yshift(T a){mn+=a;} pair<T,T>amin()const{ pair<T,T>ret{numeric_limits<T>::min(),numeric_limits<T>::max()}; if(!left.empty())ret.first=left_top(); if(!right.empty())ret.second=right_top(); return ret; } //f(x)=min[y<=x](f(y)) void ruisekimin(){while(!right.empty())right.pop();} void merge(slope_trick &a){ if(a.left.size()+a.right.size()>left.size()+right.size()){ swap(a.left,left); swap(a.right,right); swap(a.mn,mn); swap(a.left_shift,left_shift); swap(a.right_shift,right_shift); } while(!a.left.empty()){ add_left(a.left_top()); a.left.pop(); } while(!a.right.empty()){ add_right(a.right_top()); a.right.pop(); } mn+=a.mn; } }; void SOLVE(){ int n; cin>>n; vector<ll>a(n); cin>>a; sort(all(a)); slope_trick<ll>dp; rep(i,n){ dp.xshift(1); dp.ruisekimin(); dp.add(a[i]); } cout<<dp.min()<<endl; }