結果

問題 No.3048 Swing
ユーザー NakLon131
提出日時 2025-03-07 22:32:07
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 14,105 ms
コンパイル使用メモリ 387,852 KB
実行使用メモリ 8,612 KB
最終ジャッジ日時 2025-03-07 22:33:03
合計ジャッジ時間 14,034 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    input!{
		x: i128, n: i128,
	}

	// n項目まで全て0より大きい場合
	let acc_n = calc_acc_x(n);
	if x - acc_n > 0 {
		println!("{}", x - acc_n);
		return;
	}

	// 途中で0以下になる場合、
	// 0以下になる位置を見つける
	let mut left = 0i128;
	let mut right = 1i128 << 60;
	for _ in 0..70 {
		let mid = (left + right) / 2;
		if x - calc_acc_x(mid) >= 0 {
			left = mid;
		}
		else {
			right = mid;
		}
	}

	// N項目 - 0以下になる項の間の個数
	let cnt = n - right;
	if cnt % 2 == 0 {
		let right_val = x - calc_acc_x(right);
		println!("{}", right_val - (cnt / 2));
	}
	else {
		let left_val = x - calc_acc_x(left);
		println!("{}", left_val + ((cnt+1) / 2));
	}
}

fn calc_acc_x(x: i128) -> i128 {
	(1 + x) * x / 2
}

// const MOD17: usize = 1000000007;
// const MOD93: usize = 998244353;
// const INF: usize = 1 << 60;
// let dx = vec![!0, 0, 1, 0]; // 上左下右
// let dy = vec![0, !0, 0, 1]; // 上左下右
// let d = vec!{(!0, 0), (0, !0), (1, 0), (0, 1)}; // 上左下右

#[allow(unused)]
use proconio::{input, marker::Chars, marker::Usize1};

#[allow(unused)]
use std::{
	mem::swap,
	cmp::min, cmp::max,
	cmp::Reverse,
	collections::HashSet, collections::BTreeSet,
	collections::HashMap, collections::BTreeMap,
	collections::BinaryHeap,
	collections::VecDeque,
	iter::FromIterator,
};
0