結果
| 問題 |
No.1071 ベホマラー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-12 21:53:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 7,315 bytes |
| コンパイル時間 | 1,051 ms |
| コンパイル使用メモリ | 107,228 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-29 00:59:42 |
| 合計ジャッジ時間 | 2,966 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 2 |
| other | AC * 2 WA * 18 |
ソースコード
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<queue>
#include<complex>
using namespace std;
//conversion
//------------------------------------------
inline long long toint(string s) {long long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef long long ll;
typedef long long LL;
typedef vector<int > vi;
typedef vector<long long > VLL;
typedef vector<long long > vll;
typedef vector<string > ves;
typedef vector<char > vech;
typedef pair<long long , long long> pll;
typedef pair<long long , long long> PLL;
typedef map<ll , ll >mll;
typedef map<int , int >mii;
typedef map<char , int >mci;
typedef map<char , ll >mcl;
typedef vector<pair<ll , ll> > vpll;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//#define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
//constant
//------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define SIZEOF(x) sizeof(x)/sizeof(x[0])
const long long INF = 4e18;
const long long NINF = 1 - INF;
#define ENDL cout << endl;
#define CIN(a) REP(i,a.size())cin >> a[i];
//二次元座標の点を表す構造体。xとyをメンバに持つ
struct POINT{
double x;
double y;
};
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
/*
nCr , 値が大きいとオーバーフローする
n<=kなら1 (0C1や1C5= 1)
*/
ll nCr(ll n, ll r){
if ( r * 2 > n ) r = n - r;
ll dividend = 1;
ll divisor = 1;
for ( unsigned int i = 1; i <= r; ++i ) {
dividend *= (n-i+1);
divisor *= i;
}
return dividend / divisor;
}
//firstが最大値(最小値) , second が index
template<class T>
pair<T , ll> maxP(vector<T> a , ll size){
pair <T , ll> p;
ll ind = 0;
T mx = NINF;
REP(i,size){
if(mx<a[i]){
mx = a[i];
ind = i;
}
}
p.first = mx;
p.second = ind;
return p;
}
template<class T>
pair<T , ll> minP(vector<T> a , ll size){
pair <T , ll> p;
T mn = INF;
ll ind = 0;
REP(i,size){
if(mn > a[i]){
mn = a[i];
ind = i;
}
}
p.first = mn;
p.second = ind;
return p;
}
template<class T>
T sumL(vector<T> a , ll size){
T sum = 0;
REP(i,size){
sum += a[i];
}
return sum;
}
//sort済みのvll ; a のleft ~ rightにtがいくつあるか
ll counT(VLL a ,ll left , ll right , ll t ){
//sort(a.begin(),a.end());
return upper_bound(a.begin() + left , a.begin() + right,t)-lower_bound(a.begin() + left , a.begin() + right, t);
}
//切り上げ
ll kiriage(ll a , ll b){
return a/b + (a%b!=0);
}
#define COUNT(a,b) counT((a),0,a.size(),(b))
#define MAX(x) maxP(x,x.size())
#define MIN(x) minP(x,x.size())
#define SUM(x) sumL(x,x.size())
//-------要素を見つける-----------
ll search(vll &a , ll n ){//a内のnのindexを返す
std::vector<ll>::iterator iter = std::find(a.begin(), a.end(), n);
size_t index = distance(a.begin(), iter);
return index;
}
//桁数
int getdigit(ll n){
return log10(n)+1;
}
// toBinary[i]は,binaを二進数で表したときの下からi桁目のbitが入ってる
vll toBinary(ll bina){
vll ans;
for (ll i = 0; bina>0 ; i++)
{
ans.push_back(bina%2);
bina = bina/2;
}
return ans;
}
//-----------MAIN:困った時メモ------------//
//
// Sqrは2乗 sqrtはルート , 二次元座標の点は struct POINT でも表せる(メンバはx , y)
// 小さい順ならpriority_queue<ll, vll, greater<ll> > と書く
// ゲーム:grundy数 , グラフ:LCA,eulerTour,
// 最大流がScalingMaxFlow , 最小費用流がPrimalDual<flow_t , cost_t>
// めぐる式二分探索 , 半分前列挙
// bitDP , 最小全域木でコストやグラフを求める , オイラーツアー , 0-1BFS
// オイラーツアーはDFS , 全域木はDFS , 三分探索
// 区間スケジューリング問題(右端が小さい順にソート)
// 定数倍(log)を落とすことで通ることもたまにある(setやmapに注意)
// 度数 = ラジアン × 180 ÷ 円周率
// 競技プログラミングでは「数が少ない方を考えると考察が進む場合がある」という典型テクニックがあります。
// std::mapをループするときは、for(pair<type,type> x(要素): MAP)
// 期待値の線形性, 平均値は期待値の特殊な場合
// 二次元累積和の計算 : s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + a[i][j];
// (a,b) -> (c,d)の二次元累積和 : s[c][d] - s[a][d] - s[b][c] + s[a][b]
// multisetは便利 , 値の重複、upperbound、追加削除がlogN , *rbeginで最大値,*beginで最小値
#define ENDL cout << endl;
ll n , m;
ll h , w , k;
string s;
vll A ,B;
map<ll , ll>p;
ll v , e;
int main(){
ll n,k,x,y;
cin >> n >> k >> x >> y;
vll a(n);
CIN(a);
REP(i,n)a[i]--;
ll lef = 0;
ll rig = 2e9;
while(rig - lef > 1){
ll c1 = lef +(rig-lef)/3;
ll c2 = rig -(rig-lef)/3;
ll s1 = c1*y;
ll s2 = c2*y;
ll k1 = c1*k+1;
ll k2 = c2*k+1;
REP(i,n){
if(a[i]>k1){
s1 +=((a[i]-k1)/k + ((a[i]-k1)%k!=0))*x;
}
if(a[i]>k2){
s2 +=((a[i]-k2)/k + ((a[i]-k2)%k!=0))*x;
}
}
if(s1<s2){
rig = c1;
}else{
lef = c2;
}
}
ll cst = 0;
cst += rig*y;
ll p = k*rig+1;
REP(i,n){
if(a[i] > p){
cst += x*( (a[i]-p)/k+ ( (a[i]-p)%k!=0 ) );
}
}
ll cst2 = 0;
cst2 += lef*y;
p = k*lef+1;
REP(i,n){
if(a[i] > p){
cst2 += x*( (a[i]-p)/k+ ( (a[i]-p)%k!=0 ) );
}
}
cout << min(cst,cst2) << endl;
return 0;
}