結果
問題 |
No.929 よくあるボールを移動するやつ
|
ユーザー |
![]() |
提出日時 | 2019-11-23 00:04:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 180 ms / 2,000 ms |
コード長 | 588 bytes |
コンパイル時間 | 2,146 ms |
コンパイル使用メモリ | 74,792 KB |
実行使用メモリ | 59,632 KB |
最終ジャッジ日時 | 2024-10-11 06:33:01 |
合計ジャッジ時間 | 4,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = Integer.parseInt(sa[i]); } br.close(); long ans = 0; int j = 0; for (int i = 0; i < n; i++) { while (b[j] == 0) { j++; } ans += Math.abs(i - j); b[j]--; } System.out.println(ans); } }