結果
| 問題 |
No.21 平均の差
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-09-03 23:32:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,147 bytes |
| コンパイル時間 | 330 ms |
| コンパイル使用メモリ | 24,064 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2024-11-15 19:23:33 |
| 合計ジャッジ時間 | 11,276 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 1 |
コンパイルメッセージ
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]); }
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}
FF256grhy