104362024-04-02 13:21:11111Zárójel cserecpp17Accepted 100/10057ms22336 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	string S;
	cin>>S;
	deque<int>a,b;
	int i=0,x=0,y=0;
	for(char c:S){
		if(c=='('){
			x++;
			a.push_back(i);
		}
		else{
			x--;
			b.push_back(i);
		}
		y=max(y,-x);
		i++;
	}
	y=(y+1)/2;
	cout<<y<<'\n';
	while(y--){
		cout<<a.back()<<' '<<b.front()<<'\n';
		a.pop_back();
		b.pop_front();
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2056 KiB
3Accepted2ms2140 KiB
subtask233/33
4Accepted2ms2140 KiB
5Accepted3ms2244 KiB
6Accepted3ms2476 KiB
subtask344/44
7Accepted3ms2552 KiB
8Accepted3ms2816 KiB
9Accepted3ms3036 KiB
10Accepted3ms3020 KiB
11Accepted3ms3196 KiB
12Accepted3ms3244 KiB
subtask423/23
13Accepted8ms8540 KiB
14Accepted24ms10596 KiB
15Accepted8ms12508 KiB
16Accepted35ms14512 KiB
17Accepted12ms18008 KiB
18Accepted13ms19172 KiB
19Accepted13ms20044 KiB
20Accepted54ms21220 KiB
21Accepted56ms22336 KiB
22Accepted57ms22304 KiB
23Accepted52ms22288 KiB
24Accepted50ms22292 KiB