Submission #721830

# Submission time Handle Problem Language Result Execution time Memory
721830 2023-04-11T07:43:05 Z TimDee Election (BOI18_election) C++17
28 / 100
3000 ms 604 KB
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\

#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
//#define int long long
//#define double long double
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 998244353;

const int N=7e4+3;
bitset<N> a;

void solve() {
    
    int n; cin>>n;
    string s; cin>>s;
    int m; cin>>m;
    forn(i,n) a[i]=s[i]=='C';
    while (m--) {
        int l,r; cin>>l>>r; --l, --r;
        int ans=0;
        int s=0, x=0;
        for (int i=l; i<=r; ++i) {
            if (a[i]) ++s, x=x?x-1:0;
            else ans+=!s, x+=!!s, s=s?s-1:0;
        }
        cout<<ans+x<<'\n';
    }

}
     
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Compilation message

election.cpp:5:1: warning: multi-line comment [-Wcomment]
    5 | //   \ __ __  \
      | ^
election.cpp:27:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   27 | const int inf = 1e18;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 328 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 328 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Execution timed out 3051 ms 604 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 5 ms 328 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Execution timed out 3051 ms 604 KB Time limit exceeded
7 Halted 0 ms 0 KB -