結果

問題 No.1834 1D Gravity
ユーザー 👑 potato167potato167
提出日時 2022-02-04 23:31:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 3,035 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 208,360 KB
実行使用メモリ 7,392 KB
最終ジャッジ日時 2023-09-02 06:03:10
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 23 ms
6,120 KB
testcase_02 AC 22 ms
6,164 KB
testcase_03 AC 22 ms
6,216 KB
testcase_04 AC 22 ms
6,128 KB
testcase_05 AC 23 ms
6,104 KB
testcase_06 AC 23 ms
6,116 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 30 ms
7,184 KB
testcase_14 AC 28 ms
7,144 KB
testcase_15 AC 26 ms
6,588 KB
testcase_16 AC 22 ms
5,864 KB
testcase_17 AC 22 ms
5,864 KB
testcase_18 AC 26 ms
6,656 KB
testcase_19 AC 24 ms
6,852 KB
testcase_20 AC 28 ms
7,392 KB
testcase_21 AC 22 ms
5,968 KB
testcase_22 AC 22 ms
5,644 KB
testcase_23 AC 21 ms
5,444 KB
testcase_24 AC 20 ms
5,560 KB
testcase_25 AC 20 ms
5,552 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


struct XorShift {
private:
  constexpr static double R = 1.0 / 0xffffffff;
  uint64_t x;

public:
  explicit XorShift(uint64_t seed = 88172645463325252ull) : x(seed) {}

  template< typename T = uint64_t >
  inline T get() { // [0, 2^64)
    x ^= x << 7ull;
    x ^= x >> 9ull;
    return x;
  }

  inline uint32_t get(uint32_t r) { // [0, r)
    return ((uint64_t) get< uint32_t >() * r) >> 32ull;
  }

  inline uint32_t get(uint32_t l, uint32_t r) { // [l, r)
    return l + get(r - l);
  }

  inline double probability() { // [0.0, 1.0]
    return get< uint32_t >() * R;
  }
};


template<class T>
void shuffle_vector(vector<T> &p,XorShift &table){
	int L=p.size();
	for(int i=0;i<L;i++){
		int ind=table.get(i,L);
		swap(p[ind],p[i]);
	}
	return ;
}


pair<int,int> f(vector<int> &p);

vector<int> op(vector<int> &p){
	int m=p.size();
	vector<int> q(m);
	for(int i=1;i<m-1;i++){
		if(p[i-1]<p[i+1]) chmax(q[i+1],p[i]);
		else chmax(q[i-1],p[i]);
	}
	return q;
}

vector<vector<int>> div(vector<int> p){
	vector<vector<int>> G;
	vector<int> tmp;
	rep(i,p.size()){
		if(tmp.size()==0){
			if(p[i]!=0) tmp.push_back(0),tmp.push_back(p[i]);
			continue;
		}
		tmp.push_back(p[i]);
		if(p[i]==0){
			G.push_back(tmp);
			tmp={};
		}
	}
	return G;
}

void solve();

//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,T=1;
	cin>>N;
	vector<int> p(N+2);
	if(T) rep(i,N) cin>>p[i+1];
	else{
		vector<int> q(N);
		rep(i,N) q[i]=i+1;
		XorShift table(time(0));
		shuffle_vector(q,table);
		rep(i,N) p[i+1]=q[i];
	}
	if(N==2){
		cout<<"0 1\n";
		return ;
	}
	auto G=div(op(p));
	int ans_t=0,ans_c=0;
	for(auto x:G){
		auto tmp=f(x);
		chmax(ans_t,tmp.first);
		ans_c+=tmp.second;
		//for(auto y:x) cout<<y<<" ";
		//cout<<"\n";
	}
	cout<<ans_t+1<<" "<<ans_c<<"\n";
}

pair<int,int> f(vector<int> &p){
	int l=0,r=1;
	int n=p.size();
	rep(i,n){
		if(i%2==0){
			if(p[l]<p[i]) l=i;
		}else{
			if(p[r]<p[i]) r=i;
		}
	}
	if(l>r) swap(l,r);
	return {max(l-1,n-2-r)+(r-l)/2,1};
}

0