結果
問題 |
No.505 カードの数式2
|
ユーザー |
|
提出日時 | 2017-06-15 07:55:14 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 891 bytes |
コンパイル時間 | 1,013 ms |
コンパイル使用メモリ | 120,852 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 20:03:43 |
合計ジャッジ時間 | 2,625 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 3 |
ソースコード
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long inf = 1L<<60; long ans = -inf; void main() { int N = readln.chomp.to!int; auto a = readln.split.map!(to!long).array; dfs(N, a, 1, a[0]); writeln(ans); } void dfs(int N, long[] a, int idx, long value) { if (idx == N) { ans = max(ans, value); return; } dfs(N, a, idx + 1, value + a[idx]); dfs(N, a, idx + 1, value - a[idx]); dfs(N, a, idx + 1, value * a[idx]); } void readVars(T...)(auto ref T args) { auto line = readln.split; foreach(ref arg ; args){ arg = line.front.to!(typeof(arg)); line.popFront; } if(!line.empty){ writeln(line); throw new Exception("args num < input num"); } }