結果
問題 |
No.484 収穫
|
ユーザー |
![]() |
提出日時 | 2017-02-08 20:31:48 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,214 bytes |
コンパイル時間 | 7,500 ms |
コンパイル使用メモリ | 77,784 KB |
実行使用メモリ | 43,864 KB |
最終ジャッジ日時 | 2024-12-25 16:56:26 |
合計ジャッジ時間 | 9,776 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 3 |
ソースコード
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class _483 { public static void main(String[] args) throws IOException { new _483().solve(); } void solve() throws IOException { try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(); A = new int[n]; for (int i = 0; i < n; i++) { A[i] = in.nextInt(); } int ans = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if (ok(i, A[i], -1, -1) && ok(i + 1, A[i] - 2 * i - 1, 1, -1)) { ans = Math.min(ans, A[i]); } if (ok(i, A[i], 1, -1) && ok(i - 1, A[i] - 2 * (n - 1 - i) - 1, -1, -1)) { ans = Math.min(ans, A[i]); } if (ok(0, A[i] - i, 1, 1)) { ans = Math.min(ans, A[i] + (n - 1 - i)); } if (ok(0, A[i] + i, 1, -1)) { ans = Math.min(ans, A[i] + i); } } System.out.println(ans); } } int[] A; boolean ok(int x, int y, int dx, int dy) { for (; x >= 0 && x < A.length; x += dx, y += dy) { if (y < A[x]) { return false; } } return true; } // for debug static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } }