CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:Mixu_78
Submission time:2021-10-07 21:34:24 +0300
Language:Rust
Status:READY
Result:35
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1details
#2ACCEPTED0.01 s2details
#3--3details

Code

use std::cmp::min;
use std::io::{BufRead, BufReader};

fn left(s: i64, _nc: i64, l: i64, x2: i64, y2: i64) -> i64 {
    let x1 = l + 1;
    let y1 = x1;
    return (s) + ((x2 - x1) + (y2 - y1));
}

fn right(s: i64, nc: i64, l: i64, x2: i64, y2: i64) -> i64 {
    let x1 = l + 1;
    let y1 = x1;
    return (s + nc) - ((x2 - x1) + (y2 - y1));
}

fn get_start(n: i64, l: i64) -> i64 {
    let mut total = 0;
    for i in 0..l {
        total += 4 * (n - (1 + i * 2))
    }
    return total;
}

fn main() {
    let mut stdin = BufReader::new(std::io::stdin());
    let mut line = String::with_capacity(32);
    stdin.read_line(&mut line).unwrap();
    let mut split = line.split_whitespace();
    let n: i64 = split.next().unwrap().parse().unwrap();
    let t: i64 = split.next().unwrap().parse().unwrap();
    for _i in 0..t {
        let mut line = String::with_capacity(128);
        stdin.read_line(&mut line).unwrap();
        let mut split = line.split_whitespace();
        let y: i64 = split.next().unwrap().parse().unwrap();
        let x: i64 = split.next().unwrap().parse().unwrap();

        let l = min(min(y - 1, x - 1), min(n - 1 - (y - 1), n - 1 - (x - 1)));
        let l_size = n - l * 2;
        let nc = 4 * (n - (1 + l * 2));
        let s = get_start(n, l);
        let is_right = x - l == l_size || (y == l + 1 && x != l + 1);

        let res = if is_right {
            right(s, nc, l, x, y)
        } else {
            left(s, nc, l, x, y)
        };
		println!("{}", res + 1);
    }
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10 100
1 1
1 2
1 3
1 4
...

correct output
1
36
35
34
33
...

user output
1
36
35
34
33
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000 1000
371 263
915 322
946 880
53 738
...

correct output
773533
312166
206053
200080
593922
...

user output
773533
312166
206053
200080
593922
...
Truncated

Test 3

Group: 3

Verdict:

input
1000000000 1000
177757853 827347032
409613589 419171337
739269360 256524697
328695530 896842209
...

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
(empty)