답안 #854659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854659 2023-09-28T10:53:11 Z mychecksedad Election (BOI18_election) C++17
0 / 100
4 ms 348 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 22;


int n, q;
string s;
void solve(){
  cin >> n >> s;
  cin >> q;
  for(int i = 0; i < q; ++i){
    int l, r; cin >> l >> r;
    --l, --r;
    vector<int> a;
    for(int j = l; j <= r; ++j) a.pb(s[j] == 'T' ? -1 : 1);
    int ans = 0, sum = 0;
    for(int j = l; j <= r; ++j){
      if(sum + a[j - l] < 0) ++ans, a[j - l] = 0;
      else sum++;
    }
    sum = 0;
    for(int j = r; j >= l; --j){
      if(sum + a[j - l] < 0) ++ans;
      else sum += a[j - l];
    }
    cout << ans << '\n';
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    // en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

election.cpp: In function 'int main()':
election.cpp:40:15: warning: unused variable 'aa' [-Wunused-variable]
   40 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -