結果

問題 No.731 等差数列がだいすき
ユーザー bal4ubal4u
提出日時 2019-08-19 05:46:53
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,500 ms
コード長 895 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 04:55:46
合計ジャッジ時間 1,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
      |                        ^~

ソースコード

diff #

// 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;
}
0