98942024-03-15 14:10:38BakosCsongorZárójel cserecpp17Time limit exceeded 77/1001.1s8620 KiB
#include <iostream>
#include <fstream>
#include <vector>

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
1Accepted3ms1880 KiB
2Accepted3ms2068 KiB
3Accepted3ms2404 KiB
subtask233/33
4Accepted3ms2500 KiB
5Accepted3ms2616 KiB
6Accepted2ms2680 KiB
subtask344/44
7Accepted3ms2840 KiB
8Accepted4ms3104 KiB
9Accepted3ms3044 KiB
10Accepted3ms3336 KiB
11Accepted4ms3312 KiB
12Accepted3ms3324 KiB
subtask40/23
13Time limit exceeded1.1s5420 KiB
14Time limit exceeded1.065s5556 KiB
15Time limit exceeded1.077s5640 KiB
16Time limit exceeded1.052s8332 KiB
17Time limit exceeded1.054s8360 KiB
18Time limit exceeded1.062s8308 KiB
19Time limit exceeded1.077s8444 KiB
20Time limit exceeded1.057s8304 KiB
21Time limit exceeded1.067s8588 KiB
22Time limit exceeded1.065s8552 KiB
23Time limit exceeded1.072s8620 KiB
24Time limit exceeded1.055s8552 KiB