結果
問題 |
No.2221 Set X
|
ユーザー |
|
提出日時 | 2023-02-18 19:31:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,515 bytes |
コンパイル時間 | 2,422 ms |
コンパイル使用メモリ | 203,392 KB |
最終ジャッジ日時 | 2025-02-10 19:02:23 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 TLE * 22 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector<int>A(N); rep(i,N)cin>>A[i]; vector<vector<int>>V(N); rep(i,N){ int b=1; while(b*b<=A[i]){ if((A[i]+b)/(b+1)+(A[i]%(b+1)==0)<2*N)V[i].push_back((A[i]+b)/(b+1)+(A[i]%(b+1)==0)); if(b<2*N)V[i].push_back(b); b++; } if(A[i]+1<2*N)V[i].push_back(A[i]+1); sort(all(V[i])); V[i].erase(unique(all(V[i])),V[i].end()); } vector<int>S(2*N+1); rep(i,N-1){ vector<int>X; for(auto x:V[i])X.push_back(x); for(auto x:V[i+1])X.push_back(x); X.push_back(2*N); sort(all(X)); X.erase(unique(all(X)),X.end()); int l=X.size(); rep(j,l-1){ int px=X[j],qx=X[j+1]; if(A[i]/px<A[i+1]/px){ S[px]++; S[qx]--; } } } int k=1; ll ans=2*N; rep(i,2*N)S[i+1]+=S[i]; for(ll x=2;x<=2*N-1;x++){ if(chmin(ans,(x+1)*(S[x]+1)))k=x; } cout<<k<<"\n"; cout<<ans<<"\n"; }