Last active
December 4, 2021 10:12
-
-
Save shirshak55/b7deef209f42021ece3bcd174d326a9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![cfg_attr( | |
debug_assertions, | |
allow(dead_code, unused_variables, unreachable_code, unused_must_use) | |
)] | |
use std::{collections::HashSet, io::BufRead, thread::current}; | |
fn main() { | |
let stdin = std::io::stdin(); | |
let lock = stdin.lock(); | |
let mut lines = lock.lines(); | |
let score = lines.next().unwrap().unwrap(); | |
let score = score | |
.split(",") | |
.map(|v| v.parse::<isize>().unwrap()) | |
.collect::<Vec<_>>(); | |
let mut boards = vec![]; | |
let mut temp_vec = vec![]; | |
lines.next(); | |
for line in lines { | |
let line = line.unwrap(); | |
if line == "" { | |
let temp = temp_vec.join(" "); | |
let temp = temp | |
.split(" ") | |
.flat_map(|v| (v).parse::<isize>().ok()) | |
.map(|v| (v, false)) | |
.collect::<Vec<_>>(); | |
boards.push(temp); | |
temp_vec = vec![]; | |
} else { | |
temp_vec.push(line); | |
} | |
} | |
let temp = temp_vec.join(" "); | |
let temp = temp | |
.split(" ") | |
.flat_map(|v| (v).parse::<isize>().ok()) | |
.map(|v| (v, false)) | |
.collect::<Vec<_>>(); | |
boards.push(temp); | |
let mut winner_index = 99999; | |
let mut no_that_won = 0; | |
let board_len = boards.len(); | |
let mut solved_board = HashSet::new(); | |
let mut winner_count = 0; | |
'board_loop: for ss in score { | |
'break_board: for bb in boards.iter_mut().enumerate() { | |
let current_index = bb.0; | |
if solved_board.contains(¤t_index) { | |
continue; | |
} | |
let bb = bb.1; | |
for cell in bb.iter_mut() { | |
if cell.0 == ss { | |
cell.1 = true; | |
} | |
} | |
for row in bb.chunks(5) { | |
let count = row.iter().filter(|v| v.1 == true).count(); | |
if count >= 5 { | |
solved_board.insert(current_index); | |
winner_count += 1; | |
if winner_count >= board_len { | |
winner_index = current_index; | |
no_that_won = ss; | |
break 'board_loop; | |
} | |
continue 'break_board; | |
} | |
} | |
for i in 0..5 { | |
let count = bb.iter().skip(i).step_by(5).filter(|v| v.1 == true).count(); | |
if count >= 5 { | |
solved_board.insert(current_index); | |
winner_count += 1; | |
if winner_count >= board_len { | |
dbg!("WINNER COL"); | |
winner_index = current_index; | |
no_that_won = ss; | |
break 'board_loop; | |
} | |
continue 'break_board; | |
} | |
} | |
} | |
} | |
let board_sum: isize = boards[winner_index] | |
.iter() | |
.filter(|v| (v).1 == false) | |
.map(|v| (v.0)) | |
.sum(); | |
dbg!(no_that_won); | |
dbg!(board_sum); | |
dbg!((board_sum) * no_that_won); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment