Last active
July 6, 2021 18:32
-
-
Save tokugh/0cd20cb95ca579df4a202bf4b727e20c to your computer and use it in GitHub Desktop.
This file contains 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
// 位置は0-indexedで表わす。 | |
// rを固定し、文字列(0,r)の中で'ox'あるいは'xo'が現れる最も右側の位置('ox'なら'x'の位置)をmとすると、 | |
// oとxを両方含む文字列は、(l,r) = (0,r), (1,r), .., (m-1,r)のm通り。 | |
// これをr=0, .., n-1について順次加算する。 | |
fn main() { | |
proconio::input!{ _n: usize, s: String }; | |
let mut prev_c = 0; | |
let mut m = 0; | |
let mut ans = 0; | |
for (r, c) in s.bytes().enumerate() { | |
if c != prev_c { | |
m = r; | |
prev_c = c; | |
} | |
ans += m; | |
} | |
println!("{}", ans); | |
} |
This file contains 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
fn main(){proconio::input!{_:usize,s:String};let(mut b,mut m,mut a)=(0,0,0);for(r,c)in s.bytes().enumerate(){if c!=b{m=r;b=c;}a+=m;}println!("{}",a);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment