Submission #8583489


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), (10, 13), (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];
        while c[i] >= p {
            sum += (c[i] / p) * o;
            c[i] = c[i] / p + 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!("{}", now);
    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 500
Code Size 1385 Byte
Status AC
Exec Time 138 ms
Memory 8444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 20
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 AC 2 ms 4352 KB
02-random-04.txt AC 2 ms 4352 KB
02-random-05.txt AC 2 ms 4352 KB
02-random-06.txt AC 131 ms 8444 KB
02-random-07.txt AC 134 ms 8444 KB
02-random-08.txt AC 136 ms 8444 KB
02-random-09.txt AC 131 ms 6396 KB
02-random-10.txt AC 138 ms 8444 KB
02-random-11.txt AC 138 ms 8444 KB
03-max-01.txt AC 114 ms 6396 KB
03-max-02.txt AC 2 ms 4352 KB
04-min-01.txt AC 84 ms 6396 KB
04-min-02.txt AC 2 ms 4352 KB