結果

問題 No.929 よくあるボールを移動するやつ
ユーザー iicafiaxusiicafiaxus
提出日時 2019-11-22 23:17:14
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 175,564 KB
実行使用メモリ 6,584 KB
最終ジャッジ日時 2023-09-04 03:24:55
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 7 ms
5,592 KB
testcase_08 AC 14 ms
6,432 KB
testcase_09 AC 14 ms
6,344 KB
testcase_10 AC 14 ms
6,376 KB
testcase_11 AC 14 ms
6,472 KB
testcase_12 AC 14 ms
6,456 KB
testcase_13 AC 15 ms
6,584 KB
testcase_14 AC 14 ms
6,400 KB
testcase_15 AC 14 ms
6,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	long[] bs = rlong(n);
	log("bs:", bs);
	
	long[] sums = [0];
	foreach(b; bs) sums ~= sums[$ - 1] + b;
	log("sums:", sums);
	
	long ans;
	foreach(long i, sum; sums){
		log("sum:", sum, "i:", i, "abs:", abs(sum - i));
		ans += abs(sum - i);
	}
	
	ans.writeln;
}
0