98902024-03-15 13:40:00BakosCsongorZárójel cserecpp14Wrong answer 0/1003ms4284 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 answer3ms1808 KiB
2Wrong answer3ms2052 KiB
3Accepted2ms2136 KiB
subtask20/33
4Wrong answer3ms2212 KiB
5Accepted2ms2368 KiB
6Wrong answer3ms2568 KiB
subtask30/44
7Wrong answer2ms2652 KiB
8Wrong answer3ms2780 KiB
9Wrong answer2ms2892 KiB
10Wrong answer2ms2860 KiB
11Wrong answer2ms2824 KiB
12Wrong answer2ms2820 KiB
subtask40/23
13Wrong answer2ms2820 KiB
14Wrong answer3ms3076 KiB
15Wrong answer3ms3320 KiB
16Wrong answer3ms3456 KiB
17Wrong answer2ms3536 KiB
18Wrong answer2ms3492 KiB
19Wrong answer3ms3748 KiB
20Wrong answer3ms3964 KiB
21Wrong answer2ms4076 KiB
22Wrong answer3ms4080 KiB
23Wrong answer2ms4164 KiB
24Wrong answer2ms4284 KiB