98872024-03-15 11:19:23BakosCsongorZárójel cserecpp17Wrong answer 0/1003ms4264 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 answer3ms1676 KiB
2Wrong answer3ms1844 KiB
3Accepted3ms2060 KiB
subtask20/33
4Wrong answer3ms2296 KiB
5Accepted3ms2500 KiB
6Wrong answer2ms2540 KiB
subtask30/44
7Wrong answer3ms2820 KiB
8Wrong answer3ms2804 KiB
9Wrong answer3ms3004 KiB
10Wrong answer2ms3092 KiB
11Wrong answer2ms3220 KiB
12Wrong answer2ms3228 KiB
subtask40/23
13Wrong answer3ms3360 KiB
14Wrong answer2ms3404 KiB
15Wrong answer3ms3652 KiB
16Wrong answer3ms3864 KiB
17Wrong answer3ms3892 KiB
18Wrong answer3ms3888 KiB
19Wrong answer3ms4140 KiB
20Wrong answer3ms4264 KiB
21Wrong answer3ms4140 KiB
22Wrong answer3ms4072 KiB
23Wrong answer3ms4028 KiB
24Wrong answer3ms4028 KiB