Submission #469735

#TimeUsernameProblemLanguageResultExecution timeMemory
469735MohamedFaresNebiliElection (BOI18_election)C++14
0 / 100
3090 ms15948 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define pb push_back #define pp pop_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define all(x) (x).begin() , (x).end() const ll MOD = 998244353; const long double EPS = 0.000000001; const double PI = 3.14159265358979323846; const int nx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 }; const int ny[8] = { 1, 2, 2, 1, -1, -2, -2, -1 }; int32_t main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); ll n, q; string s; cin>>n>>s>>q; int res[n+1][n+1]; for(int _=0;_<n;_++) { for(int v=_;v<n;v++) { ll a, b; a=_, b=v; ll cap=0, tony=0; int vis[n]; memset(vis, 0, sizeof vis); for(int i=a;i<=b;i++) { if(s[i]=='C') cap++; if(s[i]=='T') { tony++; if(tony>cap) { vis[i]=1; tony--; } } } cap=0, tony=0; ll ans=0; for(int i=b;i>=a;i--) { if(s[i]=='C') cap++; if(s[i]=='T'&&!vis[i]) { tony++; if(tony>cap) { vis[i]=1; tony--; } } } for(int i=a;i<=b;i++) if(vis[i]) ans++; res[a][b]=ans; } } while(q--) { ll a, b; cin>>a>>b; a--; b--; cout<<res[a][b]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...