QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#263828 | #7738. Equivalent Rewriting | ucup-team635# | WA | 0ms | 2172kb | Rust | 3.6kb | 2023-11-25 08:46:29 | 2023-11-25 08:46:29 |
Judging History
answer
mod util {
pub trait Join {
fn join(self, sep: &str) -> String;
}
impl<T, I> Join for I
where
I: Iterator<Item = T>,
T: std::fmt::Display,
{
fn join(self, sep: &str) -> String {
let mut s = String::new();
use std::fmt::*;
for (i, v) in self.enumerate() {
if i > 0 {
write!(&mut s, "{}", sep).ok();
}
write!(&mut s, "{}", v).ok();
}
s
}
}
}
// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
use std::str::FromStr;
pub struct Scanner<'a> {
it: std::str::SplitWhitespace<'a>,
}
impl<'a> Scanner<'a> {
pub fn new(s: &'a String) -> Scanner<'a> {
Scanner {
it: s.split_whitespace(),
}
}
pub fn next<T: FromStr>(&mut self) -> T {
self.it.next().unwrap().parse::<T>().ok().unwrap()
}
pub fn next_bytes(&mut self) -> Vec<u8> {
self.it.next().unwrap().bytes().collect()
}
pub fn next_chars(&mut self) -> Vec<char> {
self.it.next().unwrap().chars().collect()
}
pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
(0..len).map(|_| self.next()).collect()
}
}
}
// ---------- end scannner ----------
use std::collections::*;
use std::io::Write;
type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;
fn main() {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
let mut sc = scanner::Scanner::new(&s);
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
run(&mut sc, &mut out);
}
fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
let t: u32 = sc.next();
for _ in 0..t {
let n: usize = sc.next();
let m: usize = sc.next();
let mut res = vec![0; m];
let mut op = vec![];
for _ in 0..n {
let k: usize = sc.next();
let mut p = vec![0usize; k];
for (i, p) in p.iter_mut().enumerate() {
*p = sc.next::<usize>() - 1;
res[*p] = i + 1;
}
op.push(p);
}
let res = res;
let mut cnt = vec![0; n];
let mut list = vec![vec![]; m];
let mut h = std::collections::BinaryHeap::new();
for (x, (cnt, p)) in cnt.iter_mut().zip(op.iter()).enumerate() {
for (i, &p) in p.iter().enumerate() {
if res[p] != i + 1 {
*cnt += 1;
list[p].push(x);
}
}
if *cnt == 0 {
h.push(!x);
}
}
let mut ans = vec![];
while let Some(v) = h.pop() {
let v = !v;
ans.push(v + 1);
for (i, &p) in op[v].iter().enumerate() {
if i + 1 == res[p] {
for u in list[p].drain(..) {
cnt[u] -= 1;
if cnt[u] == 0 {
h.push(!u);
}
}
}
}
}
ans.reverse();
if ans.windows(2).any(|a| a[0] > a[1]) {
writeln!(out, "Yes").ok();
use util::*;
writeln!(out, "{}", ans.iter().join(" ")).ok();
} else {
writeln!(out, "No").ok();
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 2172kb
input:
3 3 6 3 3 1 5 2 5 3 2 2 6 2 3 3 1 3 2 2 3 1 1 3 2 2 1
output:
Yes 3 1 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 1972kb
input:
1 10 5 2 2 4 4 1 3 4 2 1 2 3 2 1 4 4 5 2 4 3 3 2 5 4 3 5 4 2 3 1 3 2 5 1 4 2 3 5 1 4
output:
Yes 8 7 6 5 4 3 2 1 9 10
result:
ok OK. (1 test case)
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 2160kb
input:
1 20 5 5 4 1 2 5 3 2 5 3 3 5 1 2 5 4 5 1 3 2 3 4 2 5 5 3 1 5 4 2 5 5 1 2 3 4 1 3 4 5 1 2 3 4 4 1 3 5 2 5 2 4 2 3 5 1 3 2 4 5 5 2 3 4 1 5 4 5 2 4 3 1 2 2 4 3 4 4 5 3 1 5 4 1 5 3 2 3 5 1 3
output:
Yes 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 3 1 4 2 20
result:
wrong answer two transactions are not equivalent. (test case 1)