Submission #8582414


Source Code Expand

Copy
use std::io::*;
use std::str::FromStr;

fn main() {
    let m: usize = read();
    let mut d: Vec<usize> = vec![0; m];
    let mut c: Vec<usize> = vec![0; m];

    for i in 0..m {
        d[i] = read();
        c[i] = read();
    }

    let mut sum = 0;
    let po = [(10, 10), (10, 11), (4, 4), (12, 16), (10, 14), (4, 5), (28, 48), (64, 119), (2, 2)];

    for i in 0..m {
        if d[i] == 0 {
            sum += c[i];
            c[i] = 0;
            continue;
        }
        let (p, o) = po[d[i]-1];
        sum += (c[i] / p) * o;
        c[i] %= p;
    }/*
    for i in 0..m {
        println!("{}:{}", d[i], c[i]);
    }*/
    let mut now = 0;
    for i in 0..m {
        while c[i] > 0 {
            now += d[i];
            c[i] -= 1;
            sum += 1;

            while now > 9 {
                now = now % 10 + now / 10;
                sum += 1;
            }
        }
    }
    println!("{}", sum-1);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Submission Info

Submission Time
Task D - Digit Sum Replace
User mds_boy
Language Rust (1.15.1)
Score 0
Code Size 1294 Byte
Status WA
Exec Time 112 ms
Memory 8444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 7
WA × 13
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-corner-01.txt, 01-corner-02.txt, 01-corner-03.txt, 02-random-01.txt, 02-random-02.txt, 02-random-03.txt, 02-random-04.txt, 02-random-05.txt, 02-random-06.txt, 02-random-07.txt, 02-random-08.txt, 02-random-09.txt, 02-random-10.txt, 02-random-11.txt, 03-max-01.txt, 03-max-02.txt, 04-min-01.txt, 04-min-02.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 2 ms 4352 KB
00-sample-02.txt AC 2 ms 4352 KB
01-corner-01.txt AC 2 ms 4352 KB
01-corner-02.txt AC 2 ms 4352 KB
01-corner-03.txt AC 2 ms 4352 KB
02-random-01.txt AC 2 ms 4352 KB
02-random-02.txt AC 2 ms 4352 KB
02-random-03.txt WA 2 ms 4352 KB
02-random-04.txt WA 2 ms 4352 KB
02-random-05.txt WA 2 ms 4352 KB
02-random-06.txt WA 108 ms 8444 KB
02-random-07.txt WA 110 ms 8444 KB
02-random-08.txt WA 111 ms 8444 KB
02-random-09.txt WA 106 ms 6396 KB
02-random-10.txt WA 112 ms 8444 KB
02-random-11.txt WA 111 ms 8444 KB
03-max-01.txt WA 84 ms 6396 KB
03-max-02.txt WA 2 ms 4352 KB
04-min-01.txt WA 78 ms 6396 KB
04-min-02.txt WA 2 ms 4352 KB