結果

問題 No.3144 Parentheses Modification and Rotation (01 Ver.)
ユーザー Nauclhlt🪷
提出日時 2025-03-27 00:09:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 195,004 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-13 23:26:16
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main()
{
    int N;
    cin >> N;

    assert(1 <= N && N <= 100000);

    string S;
    cin >> S;

    assert(S.size() == N);

    if (N % 2 == 1)
    {
        cout << "-1" << "\n";
        return 0;
    }

    int open = 0;
    int close = 0;
    for (int i = 0; i < S.size(); i++)
    {
        assert(S[i] == '(' || S[i] == ')');
        if (S[i] == '(') open++;
        else if (S[i] == ')') close++;
    }

    int ans = abs(open - close) / 2;

    cout << ans << endl;
}
0