結果

問題 No.3144 Parentheses Modification and Rotation (01 Ver.)
ユーザー Blue_S
提出日時 2025-05-16 22:10:56
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 13,258 ms
コンパイル使用メモリ 394,396 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-27 10:15:15
合計ジャッジ時間 13,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `r`
  --> src/main.rs:16:9
   |
16 |         r: usize,
   |         ^ help: if this is intentional, prefix it with an underscore: `_r`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `m`
  --> src/main.rs:17:9
   |
17 |         m: usize,
   |         ^ help: if this is intentional, prefix it with an underscore: `_m`

warning: type alias `Map` is never used
 --> src/main.rs:5:6
  |
5 | type Map<K, V> = BTreeMap<K, V>;
  |      ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
 --> src/main.rs:6:6
  |
6 | type Set<T> = BTreeSet<T>;
  |      ^^^

warning: type alias `Deque` is never used
 --> src/main.rs:7:6
  |
7 | type Deque<T> = VecDeque<T>;
  |      ^^^^^

warning: type alias `Heap` is never used
 --> src/main.rs:8:6
  |
8 | type Heap<T> = BinaryHeap<T>;
  |      ^^^^

warning: constant `MOD` is never used
  --> src/main.rs:10:7
   |
10 | const MOD: u64 = 998_244_353;
   |       ^^^

warning: unused comparison that must be used
  --> src/main.rs:32:17
   |
32 |                 *c == b')';
   |                 ^^^^^^^^^^ the comparison produces a value
   |
   = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
   |
32 |                 let _ = *c == b')';
   |                 +++++++

warning: unused comparison that must be used
  --> src/main.rs:45:17
   |
45 |                 *c == b'(';
   |                 ^^^^^^^^^^ the comparison produces a value
   |
help: use `let _ = ...` to ignore the resulting value
   |
45 |                 let _ = *c == b'(';
   |                 +++++++

ソースコード

diff #

use proconio::marker::*;
use proconio::*;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;
type Heap<T> = BinaryHeap<T>;

const MOD: u64 = 998_244_353;

fn main() {
    input! {
        n: usize,
        mut s: Bytes,
        r: usize,
        m: usize,
    }

    if n & 1 == 1 {
        println!("-1");
        return;
    }

    let mut ans = 0usize;

    let x = s.iter().filter(|c| **c == b'(').count();
    if x * 2 > n {
        let mut d = x - n / 2;
        for c in s.iter_mut().rev() {
            if *c == b'(' {
                *c == b')';
                ans += 1;
                d -= 1;
                if d == 0 {
                    break;
                }
            }
        }
    }
    if x * 2 < n {
        let mut d = n / 2 - x;
        for c in s.iter_mut() {
            if *c == b')' {
                *c == b'(';
                ans += 1;
                d -= 1;
                if d == 0 {
                    break;
                }
            }
        }
    }

    println!("{}", ans);
}
0