9889 | 2024-03-15 13:22:35 | BakosCsongor | Zárójel csere | cpp17 | Wrong answer 0/100 | 3ms | 3180 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;
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1952 KiB | ||||
2 | Wrong answer | 3ms | 2132 KiB | ||||
3 | Accepted | 3ms | 2292 KiB | ||||
subtask2 | 0/33 | ||||||
4 | Wrong answer | 3ms | 2372 KiB | ||||
5 | Accepted | 3ms | 2588 KiB | ||||
6 | Wrong answer | 2ms | 2704 KiB | ||||
subtask3 | 0/44 | ||||||
7 | Wrong answer | 2ms | 2668 KiB | ||||
8 | Wrong answer | 2ms | 2668 KiB | ||||
9 | Wrong answer | 3ms | 2800 KiB | ||||
10 | Wrong answer | 2ms | 2832 KiB | ||||
11 | Wrong answer | 2ms | 2836 KiB | ||||
12 | Wrong answer | 2ms | 2836 KiB | ||||
subtask4 | 0/23 | ||||||
13 | Wrong answer | 2ms | 2836 KiB | ||||
14 | Wrong answer | 2ms | 2836 KiB | ||||
15 | Wrong answer | 2ms | 2836 KiB | ||||
16 | Wrong answer | 3ms | 2864 KiB | ||||
17 | Wrong answer | 3ms | 2832 KiB | ||||
18 | Wrong answer | 2ms | 2832 KiB | ||||
19 | Wrong answer | 3ms | 2832 KiB | ||||
20 | Wrong answer | 2ms | 2836 KiB | ||||
21 | Wrong answer | 3ms | 2836 KiB | ||||
22 | Wrong answer | 3ms | 2832 KiB | ||||
23 | Wrong answer | 3ms | 2960 KiB | ||||
24 | Wrong answer | 3ms | 3180 KiB |