結果

問題 No.21 平均の差
コンテスト
ユーザー sasa
提出日時 2025-03-03 10:10:05
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,521 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 39,992 KB
最終ジャッジ日時 2026-02-22 12:44:28
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	// 数値の数
	int count = 0;
	scanf("%d",&count);
	//printf("数値の数%d\n",count);
	// 振り分ける数
	int divide = 0;
	scanf("%d",&divide);
	//printf("振り分ける数%d\n",divide);
	// 数値
	int val[count];
	int *p = val;
	for(int i = 0;i < count;i++){
		scanf("%d",&p[i]);
	}
	//printf("\n");
	// 数値のソート(降順)
	for(int i = 0;i < count;i++){
		for(int j = 0;j < count;j++){
			if (p[i] > p[j])
			{
			    int x = p[j];
			    p[j] = p[i];
			    p[i] = x;
			}
		}
	}
	
	int tmp = count / divide;
	int array[divide][tmp];
	int k = 0;
	for(int i = 0;i < divide;i++){
		if(i < count - (count % divide)){
			for(int j = 0;j < tmp;j++){
				if(k < count){
					array[i][j] = p[k];
					//printf("%d ",array[i][j]);
				}
				k++;
			}
			//printf("\n");
		}else{
			for(int j = 0;j <= tmp;j++){
				if(k < count){
					array[i][j] = p[k];
					//printf("%d ",array[i][j]);
				}
				k++;
			}
			//printf("\n");
		}
	}
	int biggest = 0;
	int smallest = 0;
	if(count % divide == 0){
		for(int j = 0;j < tmp;j++){
			biggest += array[0][j];
			smallest +=array[divide - 1][j];
		}
        biggest = biggest / tmp;
		smallest = smallest / tmp;
	}else{
		for(int j = 0;j <= tmp;j++){
            if(j != tmp){
                smallest += array[divide - 1][j];
            }
            biggest += array[0][j];
		}
        biggest = biggest / (tmp + 1);
		smallest = smallest / tmp;
	}
	printf("%d",biggest - smallest);
}
0