結果
| 問題 | No.887 Collatz |
| コンテスト | |
| ユーザー |
neko_the_shadow
|
| 提出日時 | 2019-09-27 21:28:15 |
| 言語 | Java (openjdk 26.0.2.1) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| + 6µs | |
| コード長 | 681 bytes |
| 記録 | |
| コンパイル時間 | 2,824 ms |
| コンパイル使用メモリ | 87,228 KB |
| 実行使用メモリ | 43,240 KB |
| 最終ジャッジ日時 | 2026-09-03 11:48:52 |
| 合計ジャッジ時間 | 6,262 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int n0 = stdin.nextInt();
Deque<Integer> digits = new ArrayDeque<>();
digits.addLast(n0);
int n;
while ((n = digits.getLast()) > 1) {
if (n % 2 == 0) {
digits.addLast(n / 2);
} else {
digits.addLast(n * 3 + 1);
}
}
System.out.println(digits.size() - 1);
System.out.println(Collections.max(digits));
}
}
neko_the_shadow