답안 #565605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565605 2022-05-21T07:20:10 Z shrimb Election (BOI18_election) C++17
28 / 100
3000 ms 844 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 100001;
bool b[maxn];
signed main () {
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        int sm = 0;
        int ans = 0;
        for (int i = l - 1 ; i < r ; i++) {
            if (s[i] == 'T') sm--;
            else sm++;
            if (sm < 0) sm++, ans++, b[i] = 1;
        }
        sm = 0;
        for (int i = r - 1 ; i >= l - 1 ; i--) {
            if (s[i] == 'T') {if (!b[i]) sm--;}
            else sm++;
            if (sm < 0) sm++, ans++;
            b[i] = 0;
        }
        cout << ans << endl;
    }
}

Compilation message

election.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 8 ms 212 KB Output is correct
4 Correct 6 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 8 ms 212 KB Output is correct
4 Correct 6 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Execution timed out 3055 ms 844 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 212 KB Output is correct
2 Correct 8 ms 336 KB Output is correct
3 Correct 8 ms 212 KB Output is correct
4 Correct 6 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Execution timed out 3055 ms 844 KB Time limit exceeded
7 Halted 0 ms 0 KB -