9894 | 2024-03-15 14:10:38 | BakosCsongor | Zárójel csere | cpp17 | Time limit exceeded 77/100 | 1.1s | 8620 KiB |
#include <iostream>
#include <fstream>
#include <vector>
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;
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1880 KiB | ||||
2 | Accepted | 3ms | 2068 KiB | ||||
3 | Accepted | 3ms | 2404 KiB | ||||
subtask2 | 33/33 | ||||||
4 | Accepted | 3ms | 2500 KiB | ||||
5 | Accepted | 3ms | 2616 KiB | ||||
6 | Accepted | 2ms | 2680 KiB | ||||
subtask3 | 44/44 | ||||||
7 | Accepted | 3ms | 2840 KiB | ||||
8 | Accepted | 4ms | 3104 KiB | ||||
9 | Accepted | 3ms | 3044 KiB | ||||
10 | Accepted | 3ms | 3336 KiB | ||||
11 | Accepted | 4ms | 3312 KiB | ||||
12 | Accepted | 3ms | 3324 KiB | ||||
subtask4 | 0/23 | ||||||
13 | Time limit exceeded | 1.1s | 5420 KiB | ||||
14 | Time limit exceeded | 1.065s | 5556 KiB | ||||
15 | Time limit exceeded | 1.077s | 5640 KiB | ||||
16 | Time limit exceeded | 1.052s | 8332 KiB | ||||
17 | Time limit exceeded | 1.054s | 8360 KiB | ||||
18 | Time limit exceeded | 1.062s | 8308 KiB | ||||
19 | Time limit exceeded | 1.077s | 8444 KiB | ||||
20 | Time limit exceeded | 1.057s | 8304 KiB | ||||
21 | Time limit exceeded | 1.067s | 8588 KiB | ||||
22 | Time limit exceeded | 1.065s | 8552 KiB | ||||
23 | Time limit exceeded | 1.072s | 8620 KiB | ||||
24 | Time limit exceeded | 1.055s | 8552 KiB |