結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2016-05-15 11:39:56 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 991 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 101,248 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 03:30:04 |
合計ジャッジ時間 | 1,786 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 WA * 29 |
ソースコード
import std.stdio, std.string, std.conv; import std.array, std.algorithm; void main(){ auto l = readln.strip.to!int; auto arr = readln.strip.split.map!(to!int).array; uint ans; if(l == 1){ans = arr[0];} while(arr.length > 1){ int max, pos; foreach(i, x; arr){ if(max < x){ max = x; pos = i.to!int; }else if(max == x){ int sum = (pos-1 > 0 ? arr[pos-1]:0) + arr[pos] + (pos+1 < arr.length ? arr[pos+1]:0); int currSum = (i-1 > 0 ? arr[i-1]:0) + arr[i] + (i+1 < arr.length ? arr[i+1]:0); if(sum < currSum){ max = x; pos = i.to!int; } } } ans += max; if(pos+1 < arr.length){ arr = arr.remove(pos+1); } arr = arr.remove(pos); if(pos-1 >= 0){ arr = arr.remove(pos-1); } } ans.writeln; }