結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-16 11:53:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 444 ms / 2,000 ms |
| コード長 | 1,245 bytes |
| コンパイル時間 | 2,208 ms |
| コンパイル使用メモリ | 77,328 KB |
| 実行使用メモリ | 59,188 KB |
| 最終ジャッジ日時 | 2024-06-23 14:08:54 |
| 合計ジャッジ時間 | 4,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
sb.append(getCount(a, b, c)).append("\n");
}
System.out.print(sb);
}
static int getCount(int a, int b, int c) {
int min = Integer.MAX_VALUE;
min = Math.min(min, getOrderCount(a, c, b));
min = Math.min(min, getOrderCount(c, a, b));
min = Math.min(min, getOrderCount(b, a, c));
min = Math.min(min, getOrderCount(b, c, a));
if (min == Integer.MAX_VALUE) {
return -1;
} else {
return min;
}
}
static int getOrderCount(int a, int b, int c) {
int count = 0;
if (a <= b) {
count += b - a + 1;
b = a - 1;
}
if (b <= c) {
count += c - b + 1;
c = b - 1;
}
if (c <= 0) {
return Integer.MAX_VALUE;
} else {
return count;
}
}
}
htensai