Submission #47135426
Source Code Expand
// -*- coding:utf-8-unix -*-
use proconio::input;
fn calc(n: usize) -> usize {
if n % 2 == 0 {
n / 2
} else {
3 * n + 1
}
}
fn result(before: Vec<usize>) -> usize {
let n = before.last().unwrap().clone();
let a = calc(n);
if before.contains(&a) {
return before.len() + 1;
}
result([before, vec![a]].concat())
}
fn main() {
input! {
s: usize,
}
println!("{}", result(vec![s]));
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Collatz Problem |
| User | homura10059 |
| Language | Rust (rustc 1.70.0) |
| Score | 200 |
| Code Size | 486 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 2144 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 1 ms | 1860 KiB |
| 02.txt | AC | 1 ms | 1904 KiB |
| 03.txt | AC | 1 ms | 1936 KiB |
| 04.txt | AC | 1 ms | 1972 KiB |
| 05.txt | AC | 1 ms | 1876 KiB |
| 06.txt | AC | 1 ms | 2032 KiB |
| 07.txt | AC | 1 ms | 1968 KiB |
| 08.txt | AC | 1 ms | 2144 KiB |
| 09.txt | AC | 1 ms | 1860 KiB |
| s1.txt | AC | 1 ms | 1972 KiB |
| s2.txt | AC | 1 ms | 1940 KiB |
| s3.txt | AC | 1 ms | 2008 KiB |