답안 #128224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128224 2019-07-10T14:36:44 Z thanos Election (BOI18_election) C++14
28 / 100
3000 ms 1824 KB
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
struct query{
  int l;
  int r;
}q[500005];
string A;
int main(){
  //freopen("1-elections.in","r",stdin);
  int N;
  cin>>N;
  cin>>A;
  int K;
  cin>>K;
  for(int i=0; i<K; i++){
    cin>>q[i].l>>q[i].r;
  }
  for(int d=0; d<K; d++){
    bool v[100005]={false};
    int sum=0,cnt=0;
    for(int i=q[d].l; i<=q[d].r; i++){
      if(A[i-1]=='C'){
        sum--;
      }
      else{
        sum++;
      }
      if(sum>0 && A[i-1]=='T'){
        cnt++;
        v[i]=true;
        sum--;
      }
    }
    sum=0;
    for(int i=q[d].r; i>=q[d].l; i--){
      if(A[i-1]=='C'){
        sum--;
      }
      else{
        sum++;
      }
      if(sum>0 && !v[i] && A[i-1]=='T'){
        cnt++;
      }
      if((sum>0 && A[i-1]=='T') || v[i]) sum--;
    }
      cout<<cnt<<endl;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 380 KB Output is correct
2 Correct 31 ms 504 KB Output is correct
3 Correct 27 ms 504 KB Output is correct
4 Correct 28 ms 504 KB Output is correct
5 Correct 22 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 380 KB Output is correct
2 Correct 31 ms 504 KB Output is correct
3 Correct 27 ms 504 KB Output is correct
4 Correct 28 ms 504 KB Output is correct
5 Correct 22 ms 504 KB Output is correct
6 Execution timed out 3058 ms 1824 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 380 KB Output is correct
2 Correct 31 ms 504 KB Output is correct
3 Correct 27 ms 504 KB Output is correct
4 Correct 28 ms 504 KB Output is correct
5 Correct 22 ms 504 KB Output is correct
6 Execution timed out 3058 ms 1824 KB Time limit exceeded
7 Halted 0 ms 0 KB -