Submission #745433

# Submission time Handle Problem Language Result Execution time Memory
745433 2023-05-20T06:22:38 Z PredescuSebastianIon Match (CEOI16_match) C++11
0 / 100
0 ms 212 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iomanip>

using namespace std;
constexpr int nmax = 1e5 + 2;
int n,v[nmax],frecv[nmax],deschis[nmax],nr;
char s[nmax];
int main()
{
    cin.getline((s + 1),nmax);
    int n = strlen(s + 1);
    for(int i = 1; i <= n; i++)
    {
        int ch = s[i] - '0' + 1;
        v[i] = ch;
        if(frecv[ch] == 0)
        {
            deschis[++nr] = ch;
            frecv[ch]++;
        }
        else
        {
            if(deschis[nr] == ch)
            {
                frecv[ch]--;
                nr--;
            }
            else
            {
                cout << "-1";
                return 0;
            }
        }
    }
    if(nr > 0)
    {
        cout << "-1";
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        int ch = v[i];
        if(frecv[ch] == 0)
        {
            int ci = i, cnt = 0;
            while(v[ci] == ch && ci <= n)
            {
                cnt++;
                ci++;
            }
            ci--;
            int j = 1;
            for(; j <= (cnt + 1) / 2; j++)
            {
                cout << "(";
            }
            for(; j <= cnt; j++)
            {
                cout << ")";
            }
            i = ci;
            frecv[ch] = cnt % 2;
        }
        else
        {
            int ci = i, cnt = 0;
            while(v[ci] == ch && ci <= n)
            {
                cnt++;
                ci++;
            }
            ci--;
            int j = 1;
            for(; j <= cnt / 2; j++)
            {
                cout << "(";
            }
            for(; j <= cnt; j++)
            {
                cout << ")";
            }
            i = ci;
            frecv[ch] = (1 + cnt) % 2;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -