98932024-03-15 13:57:37BakosCsongorZárójel cserecpp17Time limit exceeded 77/1001.1s9252 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
1Accepted3ms1876 KiB
2Accepted2ms2120 KiB
3Accepted3ms2332 KiB
subtask233/33
4Accepted3ms2488 KiB
5Accepted3ms2740 KiB
6Accepted3ms2952 KiB
subtask344/44
7Accepted3ms3080 KiB
8Accepted4ms3212 KiB
9Accepted3ms3576 KiB
10Accepted3ms3648 KiB
11Accepted3ms3712 KiB
12Accepted4ms3832 KiB
subtask40/23
13Time limit exceeded1.1s5520 KiB
14Time limit exceeded1.065s5748 KiB
15Time limit exceeded1.07s6056 KiB
16Time limit exceeded1.062s8684 KiB
17Time limit exceeded1.08s8960 KiB
18Time limit exceeded1.054s8764 KiB
19Time limit exceeded1.078s8764 KiB
20Time limit exceeded1.075s8984 KiB
21Time limit exceeded1.08s9068 KiB
22Time limit exceeded1.06s9252 KiB
23Time limit exceeded1.034s9188 KiB
24Time limit exceeded1.072s9072 KiB