結果
| 問題 | No.731 等差数列がだいすき |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-19 05:46:53 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,500 ms |
| コード長 | 895 bytes |
| 記録 | |
| コンパイル時間 | 385 ms |
| コンパイル使用メモリ | 30,208 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-02 06:25:50 |
| 合計ジャッジ時間 | 1,254 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
コンパイルメッセージ
main.c: In function 'in':
main.c:11:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
11 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:17:24: note: in expansion of macro 'gc'
17 | int n = 0, c = gc();
| ^~
ソースコード
// yukicoder: No.731 等差数列がだいすき
// bal4u 2019.8.19
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
int N;
int y[1003];
int main()
{
int i;
ll sx, sx2, sy, sxy;
ll bo;
double a, b; // y = ax + b
double cost, c;
sx = sx2 = sy = sxy = 0;
N = in();
sx = (ll)N*(N+1)/2, sx2 = sx*(2*N+1)/3;
for (i = 1; i <= N; i++) {
y[i] = in();
sy += y[i], sxy += i*y[i];
}
bo = N*sx2 - sx*sx;
a = (double)(N*sxy - sx*sy) / bo;
b = (double)(sx2*sy - sxy*sx) / bo;
printf("%.15lf %.15lf\n", a+b, a);
cost = 0, c = a+b;
for (i = 1; i <= N; i++) {
cost += (c-y[i])*(c-y[i]);
c += a;
}
printf("%.15lf\n", cost);
return 0;
}
bal4u