結果
| 問題 |
No.3114 0→1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 01:22:26 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 994 bytes |
| コンパイル時間 | 18,377 ms |
| コンパイル使用メモリ | 399,060 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-19 01:22:51 |
| 合計ジャッジ時間 | 19,626 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
warning: unused import: `Usize1`
--> src/main.rs:3:21
|
3 | marker::{Chars, Usize1},
| ^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: constant `DIRS` is never used
--> src/main.rs:6:7
|
6 | const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: trait `OrdExt` is never used
--> src/main.rs:8:7
|
8 | trait OrdExt {
| ^^^^^^
warning: variable `N` should have a snake case name
--> src/main.rs:36:9
|
36 | N: usize,
| ^ help: convert the identifier to snake case: `n`
|
= note: `#[warn(non_snake_case)]` on by default
warning: variable `S` should have a snake case name
--> src/main.rs:37:9
|
37 | S: Chars
| ^ help: convert the identifier to snake case (notice the capitalization): `s`
ソースコード
use proconio::{
fastout, input,
marker::{Chars, Usize1},
};
const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)];
trait OrdExt {
fn chmax(&mut self, other: Self) -> bool;
fn chmin(&mut self, other: Self) -> bool;
}
impl<T: Ord> OrdExt for T {
fn chmax(&mut self, other: Self) -> bool {
if *self < other {
*self = other;
true
} else {
false
}
}
fn chmin(&mut self, other: Self) -> bool {
if *self > other {
*self = other;
true
} else {
false
}
}
}
#[fastout]
fn main() {
input! {
N: usize,
S: Chars
}
let mut ans = 0;
let mut tmp = if S[0] == '1' { 1 } else { -1 };
for i in 1..N {
if S[i] == '1' {
tmp += 1;
} else if tmp > 0 {
tmp = -1;
} else {
ans += 1;
tmp += 1;
}
}
println!("{}", ans);
}