結果
問題 | No.2221 Set X |
ユーザー | 沙耶花 |
提出日時 | 2023-02-17 22:48:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 919 bytes |
コンパイル時間 | 4,520 ms |
コンパイル使用メモリ | 268,372 KB |
実行使用メモリ | 14,080 KB |
最終ジャッジ日時 | 2024-07-19 13:59:52 |
合計ジャッジ時間 | 7,671 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int n; cin>>n; vector<int> a(n); rep(i,n)cin>>a[i]; set<int> S; rep(i,n+1){ S.insert(i); } vector<vector<int>> del(n*2); rep(i,n-1){ int d = a[i+1] - a[i] + 1; if(d >= n*2)continue; del[d].push_back(i+1); } long long ans = n*2; int X = 1; for(int i=1;i<n*2;i++){ rep(j,del[i].size())S.erase(del[i][j]); if((long long)(i+1) * (S.size()-1) > ans)continue; auto it = S.begin(); long long sum = S.size()-1; while(true){ if((*it)==n)break; sum -= a[(*it)] / i; it++; sum += a[(*it)-1] / i; } if(ans > sum * (i+1)){ ans = sum * (i+1); X = i; } } cout<<X<<endl; cout<<ans<<endl; return 0; }