98912024-03-15 13:40:28BakosCsongorZárójel cserecpp11Wrong answer 0/1003ms4096 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 answer3ms2056 KiB
3Accepted3ms2264 KiB
subtask20/33
4Wrong answer3ms2248 KiB
5Accepted3ms2480 KiB
6Wrong answer3ms2728 KiB
subtask30/44
7Wrong answer3ms2808 KiB
8Wrong answer3ms2904 KiB
9Wrong answer3ms3096 KiB
10Wrong answer3ms3348 KiB
11Wrong answer2ms3388 KiB
12Wrong answer3ms3524 KiB
subtask40/23
13Wrong answer3ms3608 KiB
14Wrong answer3ms3568 KiB
15Wrong answer3ms3568 KiB
16Wrong answer3ms3568 KiB
17Wrong answer3ms3568 KiB
18Wrong answer2ms3568 KiB
19Wrong answer2ms3564 KiB
20Wrong answer3ms3696 KiB
21Wrong answer3ms3808 KiB
22Wrong answer3ms4012 KiB
23Wrong answer2ms4096 KiB
24Wrong answer2ms4088 KiB