結果
| 問題 |
No.906 Y字グラフ
|
| コンテスト | |
| ユーザー |
ziita
|
| 提出日時 | 2019-10-12 23:24:04 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 5,709 bytes |
| コンパイル時間 | 13,052 ms |
| コンパイル使用メモリ | 382,656 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 18:06:30 |
| 合計ジャッジ時間 | 14,537 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
コンパイルメッセージ
warning: unused variable: `test`
--> src/main.rs:214:9
|
214 | let test = (3*x.0+k)%MOD*(x.0+1)%MOD;
| ^^^^ help: if this is intentional, prefix it with an underscore: `_test`
|
= note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::io::{Write, BufWriter};
// static MOD: usize = 998244353;
static MOD: usize = 1000000007;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes
.by_ref()
.map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr, ) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, ( $($t:tt),* )) => {
( $(read_value!($next, $t)),* )
};
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, usize1) => {
read_value!($next, usize) - 1
};
($next:expr, [ $t:tt ]) => {{
let len = read_value!($next, usize);
(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
}};
($next:expr, $t:ty) => {
$next().parse::<$t>().expect("Parse error")
};
}
use mod_int::ModInt;
pub mod mod_int {
use super::MOD;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
type Num = usize;
#[derive(Clone, Copy, Debug)]
pub struct ModInt<T: Copy + Clone>(pub T);
impl Add<ModInt<Num>> for ModInt<Num> {
type Output = ModInt<Num>;
fn add(self, rhs: ModInt<Num>) -> ModInt<Num> {
self + rhs.0
}
}
impl Add<Num> for ModInt<Num> {
type Output = ModInt<Num>;
fn add(self, rhs: Num) -> ModInt<Num> {
let mut t = rhs + self.0;
if t >= MOD {
t = t - MOD;
}
ModInt(t)
}
}
impl Sub<Num> for ModInt<Num> {
type Output = ModInt<Num>;
fn sub(self, rhs: Num) -> ModInt<Num> {
let rhs = if rhs >= MOD { rhs % MOD } else { rhs };
let value = if self.0 < rhs { self.0 + MOD } else { self.0 };
ModInt(value - rhs)
}
}
impl Sub<ModInt<Num>> for ModInt<Num> {
type Output = ModInt<Num>;
fn sub(self, rhs: ModInt<Num>) -> ModInt<Num> {
self - rhs.0
}
}
impl AddAssign<Num> for ModInt<Num> {
fn add_assign(&mut self, other: Num) {
*self = *self + other;
}
}
impl AddAssign<ModInt<Num>> for ModInt<Num> {
fn add_assign(&mut self, other: ModInt<Num>) {
*self = *self + other;
}
}
impl SubAssign<Num> for ModInt<Num> {
fn sub_assign(&mut self, other: Num) {
*self = *self - other;
}
}
impl SubAssign<ModInt<Num>> for ModInt<Num> {
fn sub_assign(&mut self, other: ModInt<Num>) {
*self = *self - other;
}
}
impl Div<Num> for ModInt<Num> {
type Output = ModInt<Num>;
fn div(self, rhs: Num) -> ModInt<Num> {
self * ModInt(rhs).pow(MOD - 2)
}
}
impl Div<ModInt<Num>> for ModInt<Num> {
type Output = ModInt<Num>;
fn div(self, rhs: ModInt<Num>) -> ModInt<Num> {
self / rhs.0
}
}
impl DivAssign<Num> for ModInt<Num> {
fn div_assign(&mut self, rhs: Num) {
*self = *self / rhs
}
}
impl DivAssign<ModInt<Num>> for ModInt<Num> {
fn div_assign(&mut self, rhs: ModInt<Num>) {
*self = *self / rhs
}
}
impl Mul<ModInt<Num>> for ModInt<Num> {
type Output = ModInt<Num>;
fn mul(self, rhs: ModInt<Num>) -> ModInt<Num> {
self * rhs.0
}
}
impl Mul<Num> for ModInt<Num> {
type Output = ModInt<Num>;
fn mul(self, rhs: Num) -> ModInt<Num> {
let t = (self.0 * rhs) % MOD;
ModInt(t)
}
}
impl MulAssign<Num> for ModInt<Num> {
fn mul_assign(&mut self, rhs: Num) {
*self = *self * rhs;
}
}
impl MulAssign<ModInt<Num>> for ModInt<Num> {
fn mul_assign(&mut self, rhs: ModInt<Num>) {
*self = *self * rhs;
}
}
impl ModInt<Num> {
pub fn pow(self, e: usize) -> ModInt<Num> {
let mut result = ModInt(1);
let mut cur = self;
let mut e = e;
while e > 0 {
if e & 1 == 1 {
result *= cur;
}
e >>= 1;
cur *= cur;
}
result
}
}
}
fn solve() {
input! {
n: i64,
}
let k = ((n-4)%6)as usize;
let x = ModInt(((n-4)/6 % MOD as i64) as usize);
let mut ans = (ModInt(3)*x+k)*(x+1);
if k==0 {ans = ModInt(3)*x*(x+1)+1;}
let test = (3*x.0+k)%MOD*(x.0+1)%MOD;
println!("{} ", ans.0);
}
fn main() {
// In order to avoid potential stack overflow, spawn a new thread.
let stack_size = 104_857_600; // 100 MB
let thd = std::thread::Builder::new().stack_size(stack_size);
thd.spawn(|| solve()).unwrap().join().unwrap();
}
ziita