結果

問題 No.21 平均の差
ユーザー FF256grhyFF256grhy
提出日時 2016-09-03 23:32:08
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,147 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 24,064 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-27 15:54:38
合計ジャッジ時間 6,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 6 ms
6,944 KB
testcase_02 AC 28 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf("%d%d", &n, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:31:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         INC0(i, n) { scanf("%d", &a[i]); }
      |                      ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>

#define FOR(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define REV(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define INC0(i, n) FOR(i, 0, n)
#define INC1(i, n) FOR(i, 1, (n) + 1)
#define DEC0(i, n) REV(i, 0, n)
#define DEC1(i, n) REV(i, 1, (n) + 1)

typedef long long   signed int LL;
typedef long long unsigned int LU;


struct Ave {
	int sum, num;
	bool operator<(const Ave& obj) {
		return (this -> sum) * obj.num < obj.sum * (this -> num);
	}
};

int n, k, a[9];
int b[9];
Ave ave[9];

int ex(int a, int b) {
	return b == 0 ? 1 : a * ex(a, b - 1);
}

int main() {
	scanf("%d%d", &n, &k);
	INC0(i, n) { scanf("%d", &a[i]); }
	
	Ave max = {   0, 1}; 
	Ave min = {1001, 1};
	
	INC0(i, ex(k, n)) {
		int t = i;
		INC0(j, n) {
			b[j] = t % k;
			t /= k;
		}
		
		INC0(j, k) { ave[j].sum = ave[j].num = 0; }
		INC0(j, n) {
			ave[ b[j] ].sum += a[j];
			ave[ b[j] ].num ++;
		}
		
		INC0(j, k) {
			if(ave[j].num != 0 &&    ave[j] < min  ) { min = ave[j]; }
			if(ave[j].num != 0 && ! (ave[j] < max) ) { max = ave[j]; }
		}
	}
	
	printf("%d\n", (max.sum * min.num - min.sum * max.num) / (max.num * min.num));
	
	return 0;
}
0