9888 | 2024-03-15 11:27:49 | BakosCsongor | Zárójel csere | cpp17 | Wrong answer 0/100 | 3ms | 3724 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;
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1804 KiB | ||||
2 | Wrong answer | 3ms | 2060 KiB | ||||
3 | Accepted | 3ms | 2428 KiB | ||||
subtask2 | 0/33 | ||||||
4 | Wrong answer | 3ms | 2444 KiB | ||||
5 | Accepted | 2ms | 2484 KiB | ||||
6 | Wrong answer | 3ms | 2684 KiB | ||||
subtask3 | 0/44 | ||||||
7 | Wrong answer | 3ms | 2944 KiB | ||||
8 | Wrong answer | 3ms | 3152 KiB | ||||
9 | Wrong answer | 2ms | 3192 KiB | ||||
10 | Wrong answer | 2ms | 3192 KiB | ||||
11 | Wrong answer | 2ms | 3312 KiB | ||||
12 | Wrong answer | 2ms | 3196 KiB | ||||
subtask4 | 0/23 | ||||||
13 | Wrong answer | 3ms | 3324 KiB | ||||
14 | Wrong answer | 2ms | 3432 KiB | ||||
15 | Wrong answer | 2ms | 3392 KiB | ||||
16 | Wrong answer | 2ms | 3392 KiB | ||||
17 | Wrong answer | 3ms | 3540 KiB | ||||
18 | Wrong answer | 3ms | 3704 KiB | ||||
19 | Wrong answer | 3ms | 3604 KiB | ||||
20 | Wrong answer | 2ms | 3604 KiB | ||||
21 | Wrong answer | 2ms | 3604 KiB | ||||
22 | Wrong answer | 2ms | 3600 KiB | ||||
23 | Wrong answer | 3ms | 3724 KiB | ||||
24 | Wrong answer | 3ms | 3724 KiB |