結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
yuya178
|
| 提出日時 | 2017-06-20 16:36:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,659 bytes |
| コンパイル時間 | 2,182 ms |
| コンパイル使用メモリ | 78,784 KB |
| 実行使用メモリ | 52,460 KB |
| 最終ジャッジ日時 | 2024-10-02 06:43:08 |
| 合計ジャッジ時間 | 4,533 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 3 WA * 17 |
ソースコード
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
int[] b = new int[N+1];
int sum = 0;
for(int i=1; i<=N; i++){
b[i] = in.nextInt();
sum += b[i];
}
int res=0;
int min=1000000;
for(int i=1; i<=N; i++){
if(i%2==0) continue;
int p = ((N+1)/2)*((N+1)/2);
if(sum<p) continue;
for(int j=1; j<=(i+1)/2;j++){
res+=Math.max(0,b[j]-j);
}
int flag=1;
for(int j=(i+3)/2; j<=i; j++){
res+=Math.max(0,b[j]-((i+1)/2-flag));
flag++;
}
for(int j=i+1; j<=N; j++){
res+=b[j];
}
if(res<min) min=res;
res=0;
}
out.println(min);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
yuya178