답안 #726768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726768 2023-04-19T10:38:30 Z YENGOYAN Election (BOI18_election) C++17
0 / 100
3 ms 340 KB
/*
                                    //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
                                    \\                                    //
                                    //  271828___182845__904523__53602__  \\
                                    \\  87___47____13______52____66__24_  //
                                    //  97___75____72______47____09___36  \\
                                    \\  999595_____74______96____69___67  //
                                    //  62___77____24______07____66__30_  \\
                                    \\  35___35____47______59____45713__  //
                                    //                                    \\
                                    \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 5;
const LL mod = 1e9 + 7, inf = 1e9;

vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };

void solve() {
  int n; cin >> n;
  string s; cin >> s;
  vector<int> pref(n + 1), suf(n + 1);
  for(int i = 0; i < n; ++i) {
    if(s[i] == 'C') pref[i + 1] = pref[i] + 1;
    else pref[i + 1] = pref[i] - 1;
  }
  for(int i = n - 1; i >= 0; --i) {
    if(s[i] == 'C') suf[i] = suf[i + 1] + 1;
    else suf[i] = suf[i + 1] - 1;
  }
  int q; cin >> q;
  while(q--) {
    int l, r; cin >> l >> r;
    int mn = 0;
    for(int i = l; i <= r; ++i) {
      mn = min(mn, pref[i]);
    }
    int mn1 = 0;
    for(int i = l - 1; i <= r - 1; ++i) {
      mn1 = min(mn1, suf[i]);
    }
    cout << -min({mn - pref[l - 1], mn1 - suf[r], 0}) << "\n";  
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 // int t; cin >> t; while(t--)
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -