LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/7/26 daily

CF 1248E1

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  s = ')' + s;
  vector<int> cnt(n + 1);
  auto calc = [&]() {
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 1; i <= n; ++i) {
      cnt[i] = cnt[i - 1] + (s[i] == '(' ? 1 : -1);
    }
    if (cnt[n]) {
      return 0;
    }
    int cur_min = *min_element(cnt.begin() + 1, cnt.end()), cur_cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (cnt[i] == cur_min) {
        ++cur_cnt;
      }
    }
    return cur_cnt;
  };
  int l = 0, r = l, ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      swap(s[i], s[j]);
      int res = calc();
      if (res >= ans) {
        ans = res;
        l = i;
        r = j;
      }
      swap(s[i], s[j]);
    }
  }
  cout << ans << '\n' << l << ' ' << r << '\n';
  return;
}

CF 1233D