-
Notifications
You must be signed in to change notification settings - Fork 30
Add sample code for the practice contest #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TonalidadeHidrica
wants to merge
12
commits into
rust-lang-ja:master
Choose a base branch
from
TonalidadeHidrica:feature/practice2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0182132
Add a sample code for A - Disjoint Set Union
TonalidadeHidrica c83ee72
Add a sample code for B - Fenwick Tree
TonalidadeHidrica 091376b
Add a sample code for C - Floor Sum
TonalidadeHidrica a4904ab
Add a sample code for E - MinCostFlow
TonalidadeHidrica e52eaf4
Add a sample code for G - SCC
TonalidadeHidrica ee2340d
Merge branch 'master' into feature/practice2
TonalidadeHidrica 3513bd4
Add a sample code for H - Two SAT
TonalidadeHidrica d01c6ac
Add a sample code for I - Number of Substrings
TonalidadeHidrica 57d2af7
cargo fmt & clippy
TonalidadeHidrica 22078b5
Add link to problem statement for each sample code
TonalidadeHidrica e0cfb53
Merge branch 'master' into feature/practice2
TonalidadeHidrica 3390137
Add a sample code for F - Convolution
mizar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use ac_library_rs::Dsu; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n = input.next().unwrap().parse().unwrap(); | ||
let mut dsu = Dsu::new(n); | ||
for _ in 0..input.next().unwrap().parse().unwrap() { | ||
let t = input.next().unwrap().parse().unwrap(); | ||
let u = input.next().unwrap().parse().unwrap(); | ||
let v = input.next().unwrap().parse().unwrap(); | ||
match t { | ||
0 => { | ||
dsu.merge(u, v); | ||
} | ||
1 => println!("{}", dsu.same(u, v) as i32), | ||
_ => {} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use ac_library_rs::FenwickTree; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n = input.next().unwrap().parse().unwrap(); | ||
let q = input.next().unwrap().parse().unwrap(); | ||
let mut tree = FenwickTree::<u64>::new(n, 0); | ||
for i in 0..n { | ||
let a: u64 = input.next().unwrap().parse().unwrap(); | ||
tree.add(i, a); | ||
} | ||
for _ in 0..q { | ||
match input.next().unwrap().parse().unwrap() { | ||
0 => { | ||
let p = input.next().unwrap().parse().unwrap(); | ||
let x: u64 = input.next().unwrap().parse().unwrap(); | ||
tree.add(p, x); | ||
} | ||
1 => { | ||
let l = input.next().unwrap().parse().unwrap(); | ||
let r = input.next().unwrap().parse().unwrap(); | ||
println!("{}", tree.sum(l, r)); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use ac_library_rs::floor_sum; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
for _ in 0..input.next().unwrap().parse().unwrap() { | ||
let n = input.next().unwrap().parse().unwrap(); | ||
let m = input.next().unwrap().parse().unwrap(); | ||
let a = input.next().unwrap().parse().unwrap(); | ||
let b = input.next().unwrap().parse().unwrap(); | ||
println!("{}", floor_sum(n, m, a, b)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use ac_library_rs::MinCostFlowGraph; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
|
||
const MAX: i64 = 1_000_000_000; | ||
|
||
#[allow(clippy::needless_range_loop)] | ||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n = input.next().unwrap().parse().unwrap(); | ||
let k = input.next().unwrap().parse().unwrap(); | ||
let a: Vec<Vec<i64>> = (0..n) | ||
.map(|_| input.by_ref().take(n).map(|s| s.parse().unwrap()).collect()) | ||
.collect(); | ||
|
||
let mut graph = MinCostFlowGraph::new(102); | ||
for i in 0..n { | ||
for j in 0..n { | ||
graph.add_edge(i, 50 + j, 1, MAX - a[i][j]); | ||
} | ||
} | ||
for i in 0..n { | ||
graph.add_edge(100, i, k, 0); | ||
graph.add_edge(50 + i, 101, k, 0); | ||
} | ||
graph.add_edge(100, 101, n as i64 * k, MAX); | ||
|
||
let (max_flow, min_cost) = graph.flow(100, 101, n as i64 * k); | ||
println!("{}", max_flow * MAX - min_cost); | ||
|
||
(0..n) | ||
.map(|i| { | ||
(0..n) | ||
.map(|j| match graph.get_edge(i * n + j).flow { | ||
1 => 'X', | ||
_ => '.', | ||
}) | ||
.collect() | ||
}) | ||
.for_each(|s: String| println!("{}", s)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use ac_library_rs::SccGraph; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n = input.next().unwrap().parse().unwrap(); | ||
let m = input.next().unwrap().parse().unwrap(); | ||
let mut graph = SccGraph::new(n); | ||
for _ in 0..m { | ||
let a = input.next().unwrap().parse().unwrap(); | ||
let b = input.next().unwrap().parse().unwrap(); | ||
graph.add_edge(a, b); | ||
} | ||
let scc = graph.scc(); | ||
println!("{}", scc.len()); | ||
for cc in scc { | ||
print!("{}", cc.len()); | ||
for v in cc { | ||
print!(" {}", v); | ||
} | ||
println!(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use ac_library_rs::TwoSat; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
|
||
fn main() { | ||
let mut buf = String::new(); | ||
std::io::stdin().read_to_string(&mut buf).unwrap(); | ||
let mut input = buf.split_whitespace(); | ||
|
||
let n = input.next().unwrap().parse().unwrap(); | ||
let d = input.next().unwrap().parse().unwrap(); | ||
let xs = (0..2 * n) | ||
.map(|_| input.next().unwrap().parse().unwrap()) | ||
.collect::<Vec<i32>>(); | ||
|
||
let mut sat = TwoSat::new(2 * n); | ||
for i in 0..2 * n { | ||
sat.add_clause(i, i % 2 == 0, i ^ 1, i % 2 == 0); | ||
} | ||
for (i, x) in xs.iter().enumerate() { | ||
for (j, y) in xs[..i].iter().enumerate() { | ||
if (x - y).abs() < d { | ||
sat.add_clause(i, false, j, false); | ||
} | ||
} | ||
} | ||
if sat.satisfiable() { | ||
println!("Yes"); | ||
let ans = sat.answer(); | ||
for i in 0..n { | ||
println!("{}", xs[2 * i + ans[2 * i + 1] as usize]); | ||
} | ||
} else { | ||
println!("No"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use ac_library_rs::{lcp_array, suffix_array}; | ||
TonalidadeHidrica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::io::Read; | ||
use std::iter; | ||
|
||
fn main() { | ||
let mut s = String::new(); | ||
std::io::stdin().read_to_string(&mut s).unwrap(); | ||
let s = s.trim(); | ||
let suffix_array = suffix_array(s); | ||
let ans: u64 = iter::once(0) | ||
.chain(lcp_array(s, &suffix_array)) | ||
.zip(suffix_array) | ||
.map(|(c, i)| (s.len() - i - c) as u64) | ||
.sum(); | ||
println!("{}", ans); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.