Submission #2216377
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 ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
use std::thread;
if BIG_STACK_SIZE {
thread::Builder::new()
.stack_size(32 * 1024 * 1024)
.name("solve".into())
.spawn(solve)
.unwrap()
.join()
.unwrap();
} else {
solve();
}
}
fn solve() {
let (n, m) = get!(usize, usize);
let ps = util::gets::<i64>();
let qs = util::gets::<i64>();
let xyab = get!(usize, usize, i64, i64; m);
let mut es = Vec::new();
let z = 2 * n;
for (i, p) in ps.into_iter().enumerate() {
es.push(((z, i), 0));
es.push(((i, z), p));
}
for (i, q) in qs.into_iter().enumerate() {
es.push(((n + i, z), 0));
es.push(((z, n + i), q));
}
for (x, y, a, b) in xyab {
let x = x - 1;
let y = y - 1;
es.push(((x, n + y), b));
es.push(((n + y, x), -a));
}
let mut ds = vec![1 << 60; z + 1];
ds[z] = 0;
for _ in 0..z + 1 {
let mut updated = false;
for &((f, t), d) in &es {
if ds[t] > ds[f] + d {
ds[t] = ds[f] + d;
updated = true;
}
}
if !updated || ds[z] < 0 {
break;
}
}
if ds[z] < 0 {
println!("no");
} else {
println!("yes");
}
}
Submission Info
Submission Time |
|
Task |
H - Asteroids2 |
User |
hatoo |
Language |
Rust (1.15.1) |
Score |
200 |
Code Size |
5195 Byte |
Status |
AC |
Exec Time |
35 ms |
Memory |
20732 KB |
Judge Result
Set Name |
All |
Score / Max Score |
200 / 200 |
Status |
|
Set Name |
Test Cases |
All |
00-sample-00, 00-sample-01, 10-small_yes-00, 10-small_yes-01, 10-small_yes-02, 10-small_yes-03, 10-small_yes-04, 10-small_yes-05, 10-small_yes-06, 10-small_yes-07, 10-small_yes-08, 20-small_disturb-00, 20-small_disturb-01, 20-small_disturb-02, 20-small_disturb-03, 20-small_disturb-04, 20-small_disturb-05, 20-small_disturb-06, 20-small_disturb-07, 20-small_disturb-08, 30-large_yes-00, 30-large_yes-01, 30-large_yes-02, 30-large_yes-03, 30-large_yes-04, 40-large_disturb-00, 40-large_disturb-01, 40-large_disturb-02, 40-large_disturb-03, 40-large_disturb-04, 40-large_disturb-05, 40-large_disturb-06, 40-large_disturb-07, 40-large_disturb-08, 40-large_disturb-09, 40-large_disturb-10, 40-large_disturb-11, 40-large_disturb-12, 40-large_disturb-13, 40-large_disturb-14, 40-large_disturb-15 |
Case Name |
Status |
Exec Time |
Memory |
00-sample-00 |
AC |
3 ms |
8572 KB |
00-sample-01 |
AC |
3 ms |
8572 KB |
10-small_yes-00 |
AC |
3 ms |
8572 KB |
10-small_yes-01 |
AC |
3 ms |
8572 KB |
10-small_yes-02 |
AC |
3 ms |
8572 KB |
10-small_yes-03 |
AC |
3 ms |
8572 KB |
10-small_yes-04 |
AC |
3 ms |
8572 KB |
10-small_yes-05 |
AC |
3 ms |
8572 KB |
10-small_yes-06 |
AC |
6 ms |
8572 KB |
10-small_yes-07 |
AC |
6 ms |
8572 KB |
10-small_yes-08 |
AC |
6 ms |
8572 KB |
20-small_disturb-00 |
AC |
3 ms |
8572 KB |
20-small_disturb-01 |
AC |
3 ms |
8572 KB |
20-small_disturb-02 |
AC |
3 ms |
8572 KB |
20-small_disturb-03 |
AC |
3 ms |
8572 KB |
20-small_disturb-04 |
AC |
3 ms |
8572 KB |
20-small_disturb-05 |
AC |
3 ms |
8572 KB |
20-small_disturb-06 |
AC |
6 ms |
8572 KB |
20-small_disturb-07 |
AC |
6 ms |
8572 KB |
20-small_disturb-08 |
AC |
6 ms |
8572 KB |
30-large_yes-00 |
AC |
35 ms |
20732 KB |
30-large_yes-01 |
AC |
35 ms |
20732 KB |
30-large_yes-02 |
AC |
35 ms |
20732 KB |
30-large_yes-03 |
AC |
35 ms |
20732 KB |
30-large_yes-04 |
AC |
35 ms |
20732 KB |
40-large_disturb-00 |
AC |
35 ms |
20732 KB |
40-large_disturb-01 |
AC |
35 ms |
20732 KB |
40-large_disturb-02 |
AC |
35 ms |
20732 KB |
40-large_disturb-03 |
AC |
35 ms |
20732 KB |
40-large_disturb-04 |
AC |
35 ms |
20732 KB |
40-large_disturb-05 |
AC |
35 ms |
20732 KB |
40-large_disturb-06 |
AC |
35 ms |
20732 KB |
40-large_disturb-07 |
AC |
35 ms |
20732 KB |
40-large_disturb-08 |
AC |
35 ms |
20732 KB |
40-large_disturb-09 |
AC |
35 ms |
20732 KB |
40-large_disturb-10 |
AC |
35 ms |
20732 KB |
40-large_disturb-11 |
AC |
35 ms |
20732 KB |
40-large_disturb-12 |
AC |
35 ms |
20732 KB |
40-large_disturb-13 |
AC |
35 ms |
20732 KB |
40-large_disturb-14 |
AC |
35 ms |
20732 KB |
40-large_disturb-15 |
AC |
35 ms |
20732 KB |