Submission #43847

# Submission time Handle Problem Language Result Execution time Memory
43847 2018-03-25T11:56:33 Z ngkan146 Match (CEOI16_match) C++11
0 / 100
1 ms 356 KB
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt[256], cnt2[256];
int main(){
    iostream::sync_with_stdio(0);
    cin >> s;
    for(auto v: s)
        ++ cnt[v];
    for(auto v: cnt){
        if (cnt[v] % 2){
            cout << -1;
            exit(0);
        }
    }
    string res;
    for(auto v: s){
        res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
    }
    // check
    stack <char> st;
    for(int i=0;i<res.size();i++){
        if (res[i] == '(')
            st.push(s[i]);
        else{
            if (st.top() != s[i]){
                cout << -1;
                exit(0);
            }
            st.pop();
        }
    }
    cout << res;
    //
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:9:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         ++ cnt[v];
                 ^
match.cpp:18:32: warning: array subscript has type 'char' [-Wchar-subscripts]
         res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
                                ^
match.cpp:18:42: warning: array subscript has type 'char' [-Wchar-subscripts]
         res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
                                          ^
match.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<res.size();i++){
                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Incorrect 1 ms 356 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Incorrect 1 ms 356 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Incorrect 1 ms 356 KB Output isn't correct
3 Halted 0 ms 0 KB -