結果
問題 | No.1097 Remainder Operation |
ユーザー | kaki |
提出日時 | 2020-06-28 09:11:47 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,072 bytes |
コンパイル時間 | 14,395 ms |
コンパイル使用メモリ | 379,208 KB |
実行使用メモリ | 67,072 KB |
最終ジャッジ日時 | 2024-07-07 03:22:26 |
合計ジャッジ時間 | 17,044 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 198 ms
66,944 KB |
testcase_18 | AC | 193 ms
66,944 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
#![allow(non_snake_case)] #![allow(dead_code)] #![allow(unused_macros)] #![allow(unused_imports)] use std::str::FromStr; use std::io::*; use std::collections::*; use std::cmp::*; struct Scanner<I: Iterator<Item = char>> { iter: std::iter::Peekable<I>, } macro_rules! exit { () => {{ exit!(0) }}; ($code:expr) => {{ if cfg!(local) { writeln!(std::io::stderr(), "===== Terminated =====") .expect("failed printing to stderr"); } std::process::exit($code); }} } impl<I: Iterator<Item = char>> Scanner<I> { pub fn new(iter: I) -> Scanner<I> { Scanner { iter: iter.peekable(), } } pub fn safe_get_token(&mut self) -> Option<String> { let token = self.iter .by_ref() .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::<String>(); if token.is_empty() { None } else { Some(token) } } pub fn token(&mut self) -> String { self.safe_get_token().unwrap_or_else(|| exit!()) } pub fn get<T: FromStr>(&mut self) -> T { self.token().parse::<T>().unwrap_or_else(|_| exit!()) } pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.get()).collect() } pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> { (0..row).map(|_| self.vec(col)).collect() } pub fn char(&mut self) -> char { self.iter.next().unwrap_or_else(|| exit!()) } pub fn chars(&mut self) -> Vec<char> { self.get::<String>().chars().collect() } pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> { (0..row).map(|_| self.chars()).collect() } pub fn line(&mut self) -> String { if self.peek().is_some() { self.iter .by_ref() .take_while(|&c| !(c == '\n' || c == '\r')) .collect::<String>() } else { exit!(); } } pub fn peek(&mut self) -> Option<&char> { self.iter.peek() } } const MAX: usize = 40; fn main() { let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char)); let N: usize = sc.get(); let A: Vec<usize> = sc.vec(N); let mut to = vec![vec![0; N]; MAX+1]; let mut sum = vec![vec![0; N]; MAX+1]; for i in 0..N { let nx = (i + A[i]) % N; to[0][i] = nx; sum[0][i] = A[i]; } for k in 0..MAX { for i in 0..N { to[k+1][i] = to[k][to[k][i]]; sum[k+1][i] = sum[k][i] + sum[k][to[k][i]]; } } let Q: usize = sc.get(); for _ in 0..Q { let K: usize = sc.get(); let mut now = 0; let mut ans = 0; for i in 0..MAX { if (K>>i) & 1 != 0 { now = to[i][now]; ans += sum[i][now]; } } println!("{}", ans); } }