提出 #704948
ソースコード 拡げる
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int T = sc.nextInt();
int a[] = new int[N];
int ans;
for(int i = 0;i < N;i++){
a[i] = sc.nextInt();
}
ans = T;
if(N == 1){
if(a[0] + M > T){
int overT = a[0] + M - T;
ans = ans - (2 * M - overT);
}
else if (a[0] + M <= T){
ans = ans - 2 * M;
}
}
else if(N != 1){
ans = ans - M;
for(int i = N-1;i > 0;i--){
if(a[i-1] + M <= a[i] - M){//かぶってない
if(i == N-1) {
if(a[i] + M <= T){
ans = ans - 3 * M;
//System.out.println("dd");
}
else if(a[i] + M > T){
int overT = a[i] + M - T;
ans = ans - (3 * M -overT);
//System.out.println("ss");
}
}
else {
ans = ans - 2 * M;
//System.out.println("yy");
}
}
else if(a[i-1] + M > a[i] - M){//かぶってる
if(i == N - 1){
if(a[i] + M <= T){
ans = ans - (M + (a[i] - a[i-1]));
//System.out.println("hh");
}
else if(a[i] + M > T){
int overT = a[i] + M - T;
ans = ans - ((M + (a[i] - a[i-1])) -overT);
//System.out.println("xx");
}
}
else {
ans = ans - (a[i] - a[i-1]);
//System.out.println("jj");
}
}
//System.out.println(ans);
}
}
System.out.println(ans);
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - 豪邸と宅配便 |
| ユーザ | n236027h |
| 言語 | Java7 (OpenJDK 1.7.0) |
| 得点 | 100 |
| コード長 | 1508 Byte |
| 結果 | AC |
| 実行時間 | 245 ms |
| メモリ | 9172 KiB |
ジャッジ結果
| セット名 | All | ||
|---|---|---|---|
| 得点 / 配点 | 100 / 100 | ||
| 結果 |
|
| セット名 | テストケース |
|---|---|
| All | 00_sample_00, 00_sample_01, 00_sample_02, 10_random_01, 10_random_02, 10_random_03, 10_random_04, 10_random_05, 10_random_06, 10_random_07, 10_random_08, 10_random_09, 10_random_10, 20_large_01, 20_large_02, 20_large_03, 20_large_04, 20_large_05, 30_do_not_return01, 30_do_not_return02, 30_do_not_return03, 30_do_not_return04, 30_do_not_return05 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00 | AC | 209 ms | 8788 KiB |
| 00_sample_01 | AC | 221 ms | 8788 KiB |
| 00_sample_02 | AC | 217 ms | 8660 KiB |
| 10_random_01 | AC | 221 ms | 9044 KiB |
| 10_random_02 | AC | 237 ms | 8916 KiB |
| 10_random_03 | AC | 233 ms | 8916 KiB |
| 10_random_04 | AC | 224 ms | 8788 KiB |
| 10_random_05 | AC | 219 ms | 8660 KiB |
| 10_random_06 | AC | 225 ms | 8788 KiB |
| 10_random_07 | AC | 221 ms | 8660 KiB |
| 10_random_08 | AC | 221 ms | 8660 KiB |
| 10_random_09 | AC | 221 ms | 8788 KiB |
| 10_random_10 | AC | 225 ms | 9044 KiB |
| 20_large_01 | AC | 229 ms | 8916 KiB |
| 20_large_02 | AC | 229 ms | 9044 KiB |
| 20_large_03 | AC | 223 ms | 9044 KiB |
| 20_large_04 | AC | 217 ms | 9172 KiB |
| 20_large_05 | AC | 245 ms | 9044 KiB |
| 30_do_not_return01 | AC | 221 ms | 8660 KiB |
| 30_do_not_return02 | AC | 213 ms | 8788 KiB |
| 30_do_not_return03 | AC | 217 ms | 8788 KiB |
| 30_do_not_return04 | AC | 221 ms | 8660 KiB |
| 30_do_not_return05 | AC | 213 ms | 8788 KiB |