98922024-03-15 13:53:49BakosCsongorZárójel cserecpp17Wrong answer 0/1001.1s9460 KiB
#include <bits/stdc++.h>

using namespace std;

int N;
vector <char> zarojel;
vector <int> sorszam;
vector <pair<int, int>> parok;
int lepesek = 0;

void simplify()
{
    for(int j = 1; j < zarojel.size(); j++)
    {
        if(zarojel.at(j-1) == '(' and zarojel.at(j) == ')')
        {
            zarojel.erase(zarojel.begin()+j-1,zarojel.begin()+j+1);
            sorszam.erase(sorszam.begin()+j-1,sorszam.begin()+j+1);
            if(j > 2) j-=2;
            else j = 0;
        }
    }
}

void megold()
{
    while(zarojel.size() > 0)
    {
        swap(zarojel[0], zarojel[zarojel.size() - 1]);
        pair<int, int> a;
        a.first = sorszam[0];
        a.second = sorszam[sorszam.size() - 1];
        parok.push_back(a);
        simplify();
        lepesek++;
    }
}


int main()
{
    //ifstream cin("input0.txt");
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        char c;
        cin >> c;
        zarojel.push_back(c);
        sorszam.push_back(i);
    }
    simplify();
    megold();
    cout << lepesek << endl;
    for(int i = 0; i < parok.size(); i++)
    {
        cout << parok[i].first << "" << parok[i].second << endl;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1788 KiB
2Wrong answer3ms2032 KiB
3Accepted3ms2272 KiB
subtask20/33
4Wrong answer2ms2364 KiB
5Accepted3ms2492 KiB
6Wrong answer3ms2580 KiB
subtask30/44
7Wrong answer3ms2676 KiB
8Wrong answer4ms2684 KiB
9Wrong answer3ms2972 KiB
10Wrong answer3ms2872 KiB
11Wrong answer4ms3188 KiB
12Wrong answer4ms3512 KiB
subtask40/23
13Time limit exceeded1.1s5328 KiB
14Time limit exceeded1.065s5424 KiB
15Time limit exceeded1.065s5796 KiB
16Time limit exceeded1.072s8604 KiB
17Time limit exceeded1.07s8736 KiB
18Time limit exceeded1.069s8696 KiB
19Time limit exceeded1.042s8712 KiB
20Time limit exceeded1.046s8524 KiB
21Time limit exceeded1.083s9044 KiB
22Time limit exceeded1.077s9416 KiB
23Time limit exceeded1.062s9460 KiB
24Time limit exceeded1.044s9412 KiB