結果

問題 No.21 平均の差
ユーザー goodbatongoodbaton
提出日時 2015-07-29 00:12:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 71,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 20:55:14
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int n,k,a[10];

double dfs(int h,int s=0,double minav=INF,double maxav=0){
    double ret=0;
    
    if(h!=k && s==n) return -1;
    
    if(h==k){
        if(s!=n) return -1;
        
        return maxav-minav;
    }
    
    int sum=0;
    double av;
    
    for(int i=s;i<n;i++){
        sum+=a[i];
        
        av = sum/(double)(i-s+1);
        
        ret =max(dfs(h+1,i+1,min(minav,av),max(maxav,av)),ret);
    }
    
    return ret;
}

int main(){
    
    scanf("%d%d",&n,&k);
    
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    
    printf("%d\n",(int)ceil(dfs(0)));
    
    return 0;
}
0