답안 #565606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565606 2022-05-21T07:21:03 Z AbdullahMW Election (BOI18_election) C++17
28 / 100
3000 ms 2064 KB
#include <bits/stdc++.h>
 
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;
 
 
int main()
{
    fast
    //setIO("");
    
    //freopen("filename.in", "r", stdin);
    //freopen("filename.out", "w", stdout);
  
    ll n; cin >> n;
    string s; cin >> s;
    
    ll q; cin >> q;
    while (q--)
    {
        unordered_map <ll, bool> nul;
        ll l, r; cin >> l >> r;
        l--, r--;
        
        ll c = 0, t = 0, cnt = 0;
        for (ll i = l; i <= r; i++)
        {
            if (s[i] == 'C') c++;
            else 
            {
                t++;
                if (t > c) 
                {
                    nul[i] = true;
                    t--;
                    cnt++;
                }
            }
            
            
        }
        
        c = 0, t = 0;
        for (ll i = r; i >= l; i--)
        {
            if (s[i] == 'C') c++;
            else 
            {
                t++;
                if (t > c) 
                {
                    t--;
                    if (!nul[i]) cnt++;
                }
                else if (nul[i]) t--;
            }
        }
        
        cout << cnt << newl;
    }
}
    
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 360 KB Output is correct
2 Correct 49 ms 340 KB Output is correct
3 Correct 43 ms 352 KB Output is correct
4 Correct 57 ms 380 KB Output is correct
5 Correct 35 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 360 KB Output is correct
2 Correct 49 ms 340 KB Output is correct
3 Correct 43 ms 352 KB Output is correct
4 Correct 57 ms 380 KB Output is correct
5 Correct 35 ms 340 KB Output is correct
6 Execution timed out 3052 ms 2064 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 360 KB Output is correct
2 Correct 49 ms 340 KB Output is correct
3 Correct 43 ms 352 KB Output is correct
4 Correct 57 ms 380 KB Output is correct
5 Correct 35 ms 340 KB Output is correct
6 Execution timed out 3052 ms 2064 KB Time limit exceeded
7 Halted 0 ms 0 KB -