Submission #930256

# Submission time Handle Problem Language Result Execution time Memory
930256 2024-02-19T07:59:34 Z ttamx Match (CEOI16_match) C++14
10 / 100
0 ms 348 KB
#include<bits/stdc++.h>

using namespace std;

int n;
int tot[300],cnt[300];
string t,ans;
stack<int> s;

void compress(int i){
    ans[i]=')';
    while(!s.empty()&&t[s.top()]!=t[i]){
        int id=s.top();
        s.pop();
        compress(id);
    }
    if(s.empty())cout << -1,exit(0);
    cnt[t[s.top()]]-=2;
    tot[t[s.top()]]-=2;
    s.pop();
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> t;
    n=t.size();
    for(auto x:t)tot[x]++;
    for(int i=0;i<300;i++)if(tot[i]&1)cout << -1,exit(0);
    for(int i=0;i<n;i++){
        ans.push_back('(');
        if(++cnt[t[i]]>tot[t[i]]/2){
            compress(i);
        }else{
            s.emplace(i);
        }
    }
    cout << ans;
}

Compilation message

match.cpp: In function 'void compress(int)':
match.cpp:18:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |     cnt[t[s.top()]]-=2;
      |                   ^
match.cpp:19:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |     tot[t[s.top()]]-=2;
      |                   ^
match.cpp: In function 'int main()':
match.cpp:27:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   27 |     for(auto x:t)tot[x]++;
      |                      ^
match.cpp:31:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |         if(++cnt[t[i]]>tot[t[i]]/2){
      |                      ^
match.cpp:31:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |         if(++cnt[t[i]]>tot[t[i]]/2){
      |                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -