http://codeforces.com/contest/1248/problem/D1
#include <bits/stdc++.h> //#include <cmath> //#include <iostream> //#include <unordered_map> #define mem(x,y) memset(x,y,sizeof(x)) #define pb push_back #define INF 0x3f3f3f3f #define ll long long #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const int mod=1e9+7; const int N=2e5+9; int n; int ch(string &s) { string t=s+s; reverse(t.begin(),t.end()); for(int i=0;i<t.length();i++) { if(t[i]==')') t[i]='('; else t[i]=')'; } //cout<<t<<endl; int l=0; int zuo=0,you=0; int ans=0; for(int r=0;r<2*n;r++) { if(l>n-1) break; if(t[r]==')'&&zuo==0) { l=r+1; } else if(t[r]=='(') { zuo++; } else if(t[r]==')') { zuo--; } if(zuo==0&&r-l+1==n) { ans++; //cout<<l<<" "; } if(r-l+1>=n) { while(l<=r) { if(t[l]=='(') zuo--; else zuo++; l++; if(t[l]=='('&&zuo==0) break; } } } //cout<<endl<<ans<<endl; return ans; } int main() { FAST_IO; cin>>n; string s; cin>>s; int ans=ch(s); int ansx=0,ansy=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(s[i]==s[j]) continue; swap(s[i],s[j]); //cout<<i+1<<" "<<j+1<<" "<<s<<endl; int tmp=ch(s); if(ans<=tmp) { ans=tmp; ansx=i; ansy=j; } swap(s[i],s[j]); } } cout<<ans<<endl; cout<<ansx+1<<" "<<ansy+1<<endl; return 0; }
