98882024-03-15 11:27:49BakosCsongorZárójel cserecpp17Wrong answer 0/1003ms3724 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("input2.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 answer3ms1804 KiB
2Wrong answer3ms2060 KiB
3Accepted3ms2428 KiB
subtask20/33
4Wrong answer3ms2444 KiB
5Accepted2ms2484 KiB
6Wrong answer3ms2684 KiB
subtask30/44
7Wrong answer3ms2944 KiB
8Wrong answer3ms3152 KiB
9Wrong answer2ms3192 KiB
10Wrong answer2ms3192 KiB
11Wrong answer2ms3312 KiB
12Wrong answer2ms3196 KiB
subtask40/23
13Wrong answer3ms3324 KiB
14Wrong answer2ms3432 KiB
15Wrong answer2ms3392 KiB
16Wrong answer2ms3392 KiB
17Wrong answer3ms3540 KiB
18Wrong answer3ms3704 KiB
19Wrong answer3ms3604 KiB
20Wrong answer2ms3604 KiB
21Wrong answer2ms3604 KiB
22Wrong answer2ms3600 KiB
23Wrong answer3ms3724 KiB
24Wrong answer3ms3724 KiB