Task: | Lista |
Sender: | xnor |
Submission time: | 2022-01-22 14:40:24 +0200 |
Language: | Rust |
Status: | READY |
Result: | 13 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 13 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.03 s | 3 | details |
#9 | ACCEPTED | 0.07 s | 3 | details |
#10 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
use std::io::{stdin, BufRead, BufReader}; fn main() { let mut stdin = BufReader::new(stdin()); let mut cur_line = String::new(); stdin.read_line(&mut cur_line).unwrap(); let n = cur_line.trim().parse::<usize>().unwrap(); let mut res = Vec::new(); cur_line.clear(); stdin.read_line(&mut cur_line).unwrap(); let x = cur_line.trim(); res.push(to_min_int_s(x)); for i in 1..n { cur_line.clear(); stdin.read_line(&mut cur_line).unwrap(); let x = cur_line.trim(); if let Some(next) = min_greater(res[i - 1], x) { res.push(next); } else { println!("IMPOSSIBLE"); std::process::exit(0); } } for v in res { println!("{}", v); } } fn min_greater(x: i64, digs: &str) -> Option<i64> { if to_min_int(digs) > x { return Some(to_min_int(digs)); } let k = 10i64.pow(digs.len() as u32 - 1); let d = digs.chars().next()?; if d == '?' { for v in 1..=9 { if let Some(r) = min_greater_inner(x - v * k, &digs[1..]) { return Some(v * k + r); } } } else { let v = (d as u32 - b'0' as u32) as i64; if let Some(r) = min_greater_inner(x - v * k, &digs[1..]) { return Some(v * k + r); } } None } fn min_greater_inner(x: i64, digs: &str) -> Option<i64> { if to_min_int(digs) > x { return Some(to_min_int(digs)); } let k = 10i64.pow(digs.len() as u32 - 1); let d = digs.chars().next()?; if d == '?' { for v in 0..=9 { if let Some(r) = min_greater_inner(x - v * k, &digs[1..]) { return Some(v * k + r); } } } else { let v = (d as u32 - b'0' as u32) as i64; if let Some(r) = min_greater_inner(x - v * k, &digs[1..]) { return Some(v * k + r); } } None } fn to_min_int(digs: &str) -> i64 { let mut n = 0; for d in digs.chars() { match d { '?' => n *= 10, c @ '0'..='9' => n = 10 * n + (c as u32 - b'0' as u32) as i64, _ => (), } } n } fn to_min_int_s(digs: &str) -> i64 { let mut n = match digs.chars().next().unwrap() { '?' => 1, c @ '0'..='9' => (c as u32 - b'0' as u32) as i64, _ => panic!(), }; for d in digs.chars().skip(1) { match d { '?' => n *= 10, c @ '0'..='9' => n = 10 * n + (c as u32 - b'0' as u32) as i64, _ => (), } } n }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 ?? ?? ?? ?? ... |
correct output |
---|
10 11 12 13 20 ... |
user output |
---|
10 11 12 13 20 ... Truncated |
Test 2
Group: 2, 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 8?? ??8? ???? ???? ... |
correct output |
---|
800 1080 1081 1082 1083 ... |
user output |
---|
(empty) |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 ?????? ?????9? ??98??? ?????5? ... |
correct output |
---|
100000 1000090 1098000 1098050 4100001 ... |
user output |
---|
(empty) |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 ? ? ? ? ... |
correct output |
---|
1 2 3 4 5 ... |
user output |
---|
1 2 3 4 5 ... Truncated |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
2 ??? ?? |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 123 ??? 124 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
5 1?? ??? 2?? ??? ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 8
Group: 3
Verdict: ACCEPTED
input |
---|
1000 ????????? ????????? ????????? ????????? ... |
correct output |
---|
100000000 100000001 100000002 100000003 100000004 ... |
user output |
---|
100000000 100000001 100000002 100000003 100000004 ... Truncated |
Test 9
Group: 3
Verdict: ACCEPTED
input |
---|
900 ???000000 ???000000 ???000000 ???000000 ... |
correct output |
---|
100000000 101000000 102000000 103000000 104000000 ... |
user output |
---|
100000000 101000000 102000000 103000000 104000000 ... Truncated |
Test 10
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 ???1????? ???0????? ???1????? ???0????? ... |
correct output |
---|
100100000 101000000 101100000 102000000 102100000 ... |
user output |
---|
(empty) |