Submission #469735

# Submission time Handle Problem Language Result Execution time Memory
469735 2021-09-01T16:46:13 Z MohamedFaresNebili Election (BOI18_election) C++14
0 / 100
3000 ms 15948 KB
#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 time Memory Grader output
1 Execution timed out 3090 ms 15948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3090 ms 15948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3090 ms 15948 KB Time limit exceeded
2 Halted 0 ms 0 KB -