結果

問題 No.920 あかあお
ユーザー kenichikenichi
提出日時 2023-06-17 16:04:31
言語 Rust
(1.77.0 + proconio)
結果
TLE  
実行時間 -
コード長 4,587 bytes
コンパイル時間 12,210 ms
コンパイル使用メモリ 378,924 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-06-25 06:29:36
合計ジャッジ時間 16,095 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `flag` is assigned to, but never used
  --> src/main.rs:18:10
   |
18 |     let mut flag = 0;
   |             ^^^^
   |
   = note: consider using `_flag` instead
   = note: `#[warn(unused_variables)]` on by default

warning: variable `tmp` is assigned to, but never used
  --> src/main.rs:19:10
   |
19 |     let mut tmp = 0;
   |             ^^^
   |
   = note: consider using `_tmp` instead

warning: value assigned to `flag` is never read
  --> src/main.rs:28:3
   |
28 |         flag = 0;
   |         ^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: value assigned to `flag` is never read
  --> src/main.rs:32:4
   |
32 |             flag = 1;
   |             ^^^^
   |
   = help: maybe it is overwritten before being read?

warning: value assigned to `tmp` is never read
  --> src/main.rs:37:5
   |
37 |                 tmp = 1;
   |                 ^^^
   |
   = help: maybe it is overwritten before being read?

warning: value assigned to `flag` is never read
  --> src/main.rs:41:5
   |
41 |                 flag = 1;
   |                 ^^^^
   |
   = help: maybe it is overwritten before being read?

warning: value assigned to `tmp` is never read
  --> src/main.rs:47:5
   |
47 |                 tmp = 1;
   |                 ^^^
   |
   = help: maybe it is overwritten before being read?

warning: value assigned to `flag` is never read
  --> src/main.rs:51:5
   |
51 |                 flag = 1;
   |                 ^^^^
   |
   = help: maybe it is overwritten before being read?

warning: value assigned to `flag` is never read
  --> src/main.rs:58:4
   |
58 |             flag = 1;
   |             ^^^^
   |
   = help: maybe it is overwritten before being read?

ソースコード

diff #

use std::io::*;
use std::str::FromStr;
//use std::num;
//use std::cmp;
//use std::collections::VecDeque;
//use std::io::{self, BufRead};
/*
const LOW_CASE_ALPHABET: [char; 26] = [
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
	't', 'u', 'v', 'w', 'x', 'y', 'z',
];
*/
fn main() {
	let mut x: usize = read();
	let mut y: usize = read();
	let mut z: usize = read();
	let mut ans = 0;
	let mut flag = 0;
	let mut tmp = 0;

	let a = min_u_2(x, y);

	ans += a;
	x -= a;
	y -= a;

	loop {
		flag = 0;
		if x == 0 && y == 0 && z >= 2 {
			ans += z / 2;
			z -= (z / 2) * 2;
			flag = 1;
		} else if x == 0 {
			if y > z {
				x += z;
				z = 0;
				tmp = 1;
			} else {
				z -= y;
				x += y;
				flag = 1;
			}
		} else if y == 0 {
			if x > z {
				y += z;
				z = 0;
				tmp = 1;
			} else {
				z -= x;
				y += x;
				flag = 1;
			}
		} else if x >= y {
			let b = min_u_2(x, y);
			ans += b;
			x -= b;
			y -= b;
			flag = 1;
		}

		if (x != 0 && y == 0 && z == 0) || (x == 0 && y == 0 && z < 2) {
			break;
		}
	}

	print!("{}", ans);
}

pub fn ctoi(c: char) -> isize {
	let n = c as isize - '0' as isize;

	return n;
}

pub fn stoi(c: String) -> isize {
	let n = c.parse::<isize>().unwrap();

	return n;
}

pub fn find_char(sentence: Vec<char>, target: char, start: isize) -> isize {
	for _i in start as usize..sentence.len() {
		if sentence[_i] == target {
			return _i as isize;
		}
	}
	return -1;
}

pub fn hex_to_binary(hex_string: &str, x: u32) -> Option<String> {
	match i64::from_str_radix(hex_string, x) {
		Ok(decimal) => Some(format!("{}", decimal)),
		Err(_) => None,
	}
}

pub fn my_floor(x: f64) -> f64 {
	let rounded = (x * 1000.0).floor() / 1000.0;

	rounded
}

pub fn upper_lower(x: char) -> char {
	let result: char;

	if x.is_uppercase() {
		result = x.to_ascii_lowercase();
	} else if x.is_lowercase() {
		result = x.to_ascii_uppercase();
	} else {
		result = x;
	}

	result
}

pub fn maxf_2(x: f64, y: f64) -> f64 {
	let result;

	if x >= y {
		result = x;
	} else {
		result = y;
	}

	result
}

pub fn max_2(x: isize, y: isize) -> isize {
	let result;

	if x >= y {
		result = x;
	} else {
		result = y;
	}

	result
}

pub fn max_u_2(x: usize, y: usize) -> usize {
	let result;

	if x >= y {
		result = x;
	} else {
		result = y;
	}

	result
}

pub fn min_u_2(x: usize, y: usize) -> usize {
	let result;

	if x <= y {
		result = x;
	} else {
		result = y;
	}

	result
}

pub fn min_2(x: isize, y: isize) -> isize {
	let result;

	if x >= y {
		result = y;
	} else {
		result = x;
	}

	result
}

pub fn min_2_i32(x: i32, y: i32) -> i32 {
	let result;

	if x >= y {
		result = y;
	} else {
		result = x;
	}

	result
}

pub fn max_3(x: isize, y: isize, z: isize) -> isize {
	let result;
	if x >= y && y >= z {
		result = x;
	} else if x >= z && z >= y {
		result = x;
	} else if y >= x && x >= z {
		result = y;
	} else if y >= z && z >= x {
		result = y;
	} else if z >= x && x >= y {
		result = z;
	} else {
		result = z;
	}

	result
}

pub fn max_u_3(x: usize, y: usize, z: usize) -> usize {
	let result;
	if x >= y && y >= z {
		result = x;
	} else if x >= z && z >= y {
		result = x;
	} else if y >= x && x >= z {
		result = y;
	} else if y >= z && z >= x {
		result = y;
	} else if z >= x && x >= y {
		result = z;
	} else {
		result = z;
	}

	result
}

pub fn min_3(x: isize, y: isize, z: isize) -> isize {
	let result;
	if x <= y && y <= z {
		result = x;
	} else if x <= z && z <= y {
		result = x;
	} else if y <= x && x <= z {
		result = y;
	} else if y <= z && z <= x {
		result = y;
	} else if z <= x && x <= y {
		result = z;
	} else {
		result = z;
	}

	result
}

pub fn min_u_3(x: usize, y: usize, z: usize) -> usize {
	let result;
	if x <= y && y <= z {
		result = x;
	} else if x <= z && z <= y {
		result = x;
	} else if y <= x && x <= z {
		result = y;
	} else if y <= z && z <= x {
		result = y;
	} else if z <= x && x <= y {
		result = z;
	} else {
		result = z;
	}

	result
}

pub fn read_text() -> String {
	let mut word = String::new();
	std::io::stdin().read_line(&mut word).ok();
	let answer = word.trim().to_string();

	answer
}

pub fn read_array() -> Vec<char> {
	let array: String = read();
	let chars: Vec<char> = array.trim().chars().collect::<Vec<char>>();
	chars
}

pub fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}
0