結果
問題 | No.365 ジェンガソート |
ユーザー |
|
提出日時 | 2016-04-29 22:36:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 212 ms / 2,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 2,159 ms |
コンパイル使用メモリ | 74,772 KB |
実行使用メモリ | 49,044 KB |
最終ジャッジ日時 | 2024-10-12 01:40:51 |
合計ジャッジ時間 | 8,479 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.math.*; public class Main { public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int max = 0; int[] a = new int [n]; for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); max = Math.max(max,a[i]); } int sum = 0; int chain = 0; for(int i = n-1; i >-1 ; i--){ if(a[i]==max){ sum += chain; chain = 0; max--; }else{ chain++; } } if(chain>0)sum+=chain; sb.append(sum); System.out.println(sb); } }