답안 #1100012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100012 2024-10-12T11:32:28 Z vjudge1 Election (BOI18_election) C++14
28 / 100
3000 ms 2096 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define fi first
#define se second
 
using namespace std;
 
const int maxn = 7e4 + 7;
 
int n , a[maxn];
 
void query(int l , int r)
{
    vector <int> p(maxn);
    for(int i = 1; i <= n; i++) p[i] = a[i];
 
    int sum = 0;
 
    for(int i = l; i <= r; i++)
    {
        sum += p[i];
 
        if(sum < 0)
        {
            p[i] = 0;
            sum += 1;
        }
    }
 
    sum = 0;
 
    for(int i = r; i >= l; i--)
    {
        sum += p[i];
 
        if(sum < 0)
        {
            p[i] = 0;
            sum += 1;
        }
    }
 
    int ans = 0;
 
    for(int i = l; i <= r; i++)
    {
        ans += (a[i] != p[i]);
    }
    cout << ans << '\n';
}
 
void solve()
{
    cin >> n;
    string s; cin >> s;
    s = ' ' + s;
 
    for(int i = 1; i <= n; i++)
    {
        if(s[i] == 'C') a[i] = 1;
        else a[i] = -1;
    }
 
    int q; cin >> q;
 
    while(q--)
    {
        int l , r;
        cin >> l >> r;
        query(l , r);
    }
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 740 KB Output is correct
2 Correct 12 ms 788 KB Output is correct
3 Correct 10 ms 604 KB Output is correct
4 Correct 9 ms 696 KB Output is correct
5 Correct 9 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 740 KB Output is correct
2 Correct 12 ms 788 KB Output is correct
3 Correct 10 ms 604 KB Output is correct
4 Correct 9 ms 696 KB Output is correct
5 Correct 9 ms 784 KB Output is correct
6 Correct 2141 ms 2096 KB Output is correct
7 Execution timed out 3063 ms 1840 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 740 KB Output is correct
2 Correct 12 ms 788 KB Output is correct
3 Correct 10 ms 604 KB Output is correct
4 Correct 9 ms 696 KB Output is correct
5 Correct 9 ms 784 KB Output is correct
6 Correct 2141 ms 2096 KB Output is correct
7 Execution timed out 3063 ms 1840 KB Time limit exceeded
8 Halted 0 ms 0 KB -