98892024-03-15 13:22:35BakosCsongorZárójel cserecpp17Wrong answer 0/1003ms3180 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("input1.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 answer3ms1952 KiB
2Wrong answer3ms2132 KiB
3Accepted3ms2292 KiB
subtask20/33
4Wrong answer3ms2372 KiB
5Accepted3ms2588 KiB
6Wrong answer2ms2704 KiB
subtask30/44
7Wrong answer2ms2668 KiB
8Wrong answer2ms2668 KiB
9Wrong answer3ms2800 KiB
10Wrong answer2ms2832 KiB
11Wrong answer2ms2836 KiB
12Wrong answer2ms2836 KiB
subtask40/23
13Wrong answer2ms2836 KiB
14Wrong answer2ms2836 KiB
15Wrong answer2ms2836 KiB
16Wrong answer3ms2864 KiB
17Wrong answer3ms2832 KiB
18Wrong answer2ms2832 KiB
19Wrong answer3ms2832 KiB
20Wrong answer2ms2836 KiB
21Wrong answer3ms2836 KiB
22Wrong answer3ms2832 KiB
23Wrong answer3ms2960 KiB
24Wrong answer3ms3180 KiB