Submission #2173632
Source Code Expand
/**
* _ _ __ _ _ _ _ _ _ _
* | | | | / / | | (_) | (_) | | (_) | |
* | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___
* | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __|
* | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \
* |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/
* | | | | | |
* |_| |_| |_|
*
* https://github.com/hatoo/competitive-rust-snippets
*/
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
use std::io::{stdin, stdout, BufWriter, StdoutLock};
use std::str::FromStr;
use std::fmt::Debug;
#[allow(dead_code)]
pub fn line() -> String {
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.trim().to_string()
}
#[allow(dead_code)]
pub fn chars() -> Vec<char> {
line().chars().collect()
}
#[allow(dead_code)]
pub fn gets<T: FromStr>() -> Vec<T>
where
<T as FromStr>::Err: Debug,
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|t| t.parse().unwrap())
.collect()
}
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
let out = stdout();
let writer = BufWriter::new(out.lock());
f(writer)
}
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[derive(Eq, PartialEq, Clone, Debug)]
/// Equivalent to std::cmp::Reverse
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
other.0.partial_cmp(&self.0)
}
}
impl<T: Ord> Ord for Rev<T> {
fn cmp(&self, other: &Rev<T>) -> Ordering {
other.0.cmp(&self.0)
}
}
#[allow(dead_code)]
fn main() {
let n = get!(usize);
let aa = util::gets::<i64>();
let ans = (0..n)
.map(|i| {
let (_, j) = (0..n)
.filter(|&j| j != i)
.map(|j| {
let l = min(i, j);
let r = max(i, j);
(
Rev((l..r + 1)
.enumerate()
.filter_map(|(idx, k)| if idx % 2 == 1 { Some(aa[k]) } else { None })
.sum::<i64>()),
j,
)
})
.min()
.unwrap();
let l = min(i, j);
let r = max(i, j);
(l..r + 1)
.enumerate()
.filter_map(|(idx, k)| if idx % 2 == 0 { Some(aa[k]) } else { None })
.sum::<i64>()
})
.max()
.unwrap();
println!("{}", ans);
}
Submission Info
Submission Time |
|
Task |
C - 数列ゲーム |
User |
hatoo |
Language |
Rust (1.15.1) |
Score |
100 |
Code Size |
5132 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
4352 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
All |
sample-01.txt, sample-02.txt, sample-03.txt, test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt |
Case Name |
Status |
Exec Time |
Memory |
sample-01.txt |
AC |
2 ms |
4352 KB |
sample-02.txt |
AC |
2 ms |
4352 KB |
sample-03.txt |
AC |
2 ms |
4352 KB |
test-01.txt |
AC |
2 ms |
4352 KB |
test-02.txt |
AC |
2 ms |
4352 KB |
test-03.txt |
AC |
2 ms |
4352 KB |
test-04.txt |
AC |
2 ms |
4352 KB |
test-05.txt |
AC |
2 ms |
4352 KB |
test-06.txt |
AC |
2 ms |
4352 KB |
test-07.txt |
AC |
2 ms |
4352 KB |
test-08.txt |
AC |
2 ms |
4352 KB |
test-09.txt |
AC |
2 ms |
4352 KB |
test-10.txt |
AC |
2 ms |
4352 KB |
test-11.txt |
AC |
2 ms |
4352 KB |
test-12.txt |
AC |
2 ms |
4352 KB |
test-13.txt |
AC |
2 ms |
4352 KB |
test-14.txt |
AC |
2 ms |
4352 KB |
test-15.txt |
AC |
2 ms |
4352 KB |
test-16.txt |
AC |
2 ms |
4352 KB |
test-17.txt |
AC |
2 ms |
4352 KB |
test-18.txt |
AC |
2 ms |
4352 KB |
test-19.txt |
AC |
2 ms |
4352 KB |
test-20.txt |
AC |
2 ms |
4352 KB |