제출 #809092

#제출 시각아이디문제언어결과실행 시간메모리
809092nonono괄호 문자열 (CEOI16_match)C++14
37 / 100
8 ms340 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e5 + 10;

int n;
string s;

namespace sub {
    int mark[mxN];

    bool check() {
        vector<int> q;

        for(int i = 1; i <= n; i ++) {
            if(mark[i]) {
                q.push_back(i - 1);
                continue ;
            }

            if(!q.empty() && s[q.back()] == s[i - 1]) q.pop_back();
            else {
                q.push_back(i - 1);
            }
        }

        return q.size() == 0;
    }

    int main() {
        for(int i = 1; i <= n; i ++) mark[i] = 0;

        if(!check()) {
            return cout << -1, 0;
        }

        for(int i = 1; i <= n; i ++) {
            mark[i] = 1;
            mark[i] = check();
        }

        for(int i = 1; i <= n; i ++) cout << (mark[i] ? '(' : ')');
        return 0;
    }
}

int main() {
    #define taskname ""

    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);

    cin >> s;
    n = s.size();

    if(n <= 2000) sub :: main();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

match.cpp: In function 'int main()':
match.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
match.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...