結果
| 問題 |
No.31 悪のミックスジュース
|
| コンテスト | |
| ユーザー |
184
|
| 提出日時 | 2014-10-02 20:33:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,517 bytes |
| コンパイル時間 | 879 ms |
| コンパイル使用メモリ | 69,204 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 07:02:44 |
| 合計ジャッジ時間 | 1,622 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:44: warning: narrowing conversion of ‘cst[0]’ from ‘int’ to ‘long long unsigned int’ [-Wnarrowing]
44 | unsigned long long csts[101]={cst[0]};
| ~~~~~^
main.cpp:35:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | int n,v;scanf("%d%d",&n,&v);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d",&cst[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
/*
正解してたら匿名でも問題投稿ができる(実現度さらにアップ)!!!
%I64dが通らない、
作れないケースは無い?
作れないケースが無いならば、
SUM(Cn)が10^9を越えるケースは無い?
サンプルは全部あってる。
*/
int cst[101];
int idx[101];
struct smallercost{
bool operator()(const int &a, const int &b){
if(cst[a]!=cst[b])return cst[a]<cst[b];
return a<b;
}
};
int main(){
int n,v;scanf("%d%d",&n,&v);
unsigned long long sc=0;
for(int i=0;i<n;i++){
scanf("%d",&cst[i]);
idx[i]=i;
sc+=cst[i];
}
sort(idx,idx+n,smallercost());
unsigned long long csts[101]={cst[0]};
int minidx=0;
for(int i=1;i<n;i++)csts[i]=(unsigned long long)cst[i]+csts[i-1];
double mincst=(double)1000000001*100,dcsts[101];
for(int i=0;i<n;i++){
dcsts[i]=(double)csts[i]/(i+1);
if(mincst>dcsts[i])mincst=dcsts[i],minidx=i;
}
v-=n;
if(v<=0){
printf("%llu\n",sc);return 0;
}
else if(idx[0]==0){
printf("%llu\n",(unsigned long long)v*cst[0]+sc);return 0;
}
unsigned long long minc=(unsigned long long)v*csts[0],mcs;
for(int i=1;i<n;i++){
if(dcsts[i]<dcsts[0]){
mcs=v/(i+1)*csts[i];
if(v%(i+1))mcs+=csts[v%(i+1)-1];
if(minc>mcs)minc=mcs;
}
}
printf("%llu\n",minc+sc);
return 0;
}
184