답안 #737024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737024 2023-05-06T13:28:06 Z josanneo22 Election (BOI18_election) C++17
28 / 100
3000 ms 2652 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second 


void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename A>
void __print(const A &x);
template <typename A, typename B>
void __print(const pair<A, B> &p);
template <typename... A>
void __print(const tuple<A...> &t);
template <typename T>
void __print(stack<T> s);
template <typename T>
void __print(queue<T> q);
template <typename T, typename... U>
void __print(priority_queue<T, U...> q);
template <typename A>
void __print(const A &x) {
    bool first = true;
    cerr << '{';
    for (const auto &i : x) {
        cerr << (first ? "" : ","), __print(i);
        first = false;
    }
    cerr << '}';
}
template <typename A, typename B>
void __print(const pair<A, B> &p) {
    cerr << '(';
    __print(p.first);
    cerr << ',';
    __print(p.second);
    cerr << ')';
}
template <typename... A>
void __print(const tuple<A...> &t) {
    bool first = true;
    cerr << '(';
    apply([&first](const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
    cerr << ')';
}
template <typename T>
void __print(stack<T> s) {
    vector<T> debugVector;
    while (!s.empty()) {
        T t = s.top();
        debugVector.push_back(t);
        s.pop();
    }
    reverse(debugVector.begin(), debugVector.end());
    __print(debugVector);
}
template <typename T>
void __print(queue<T> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.front();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
template <typename T, typename... U>
void __print(priority_queue<T, U...> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.top();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail>
void _print(const Head &H, const Tail &...T) {
    __print(H);
    if (sizeof...(T))
        cerr << ", ";
    _print(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "Line:" << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif


#define int long long
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
	int s=0;
	char ch=getchar(),last;
	while(ch<'0'||ch>'9') last=ch,ch=getchar();
	while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return last=='-'?-s:s;
}
int num[100];
inline void rt(int x)
{
	if(x<0) putchar('-'),x=-x;;
	int len=0;
	do num[len++]=x%10;while(x/=10);
	while(len--) putchar(num[len]+'0');
}
void solve(){
    int n,q; cin>>n;
    string s; cin>>s;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        if(s[i]=='C') a[i]=1;
        else a[i]=-1;
    }
    debug(a);
    /*
    int sz=sqrt(n);
    vector<int>block(n)
    for(int i=0;i<n;i++){
        
    }*/
    cin>>q;
    while(q--){
        vector<int>null(n,0);
        int l,r; cin>>l>>r;
        l--;r--;
        int cur=0;
        for(int i=l;i<=r;i++){
            cur+=a[i]; 
            if(cur<0){
                null[i]=1;
                cur++;
            }
        }
        cur=0;
        for(int i=r;i>=l;i--){
            if(null[i]) continue;
            cur+=a[i]; 
            if(cur<0){
                null[i]=1;
                cur++;
            }
        }
        cout<<accumulate(null.begin(),null.end(),0LL)<<'\n';
    }
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 340 KB Output is correct
2 Correct 12 ms 392 KB Output is correct
3 Correct 10 ms 372 KB Output is correct
4 Correct 13 ms 468 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 340 KB Output is correct
2 Correct 12 ms 392 KB Output is correct
3 Correct 10 ms 372 KB Output is correct
4 Correct 13 ms 468 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Execution timed out 3058 ms 2652 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 340 KB Output is correct
2 Correct 12 ms 392 KB Output is correct
3 Correct 10 ms 372 KB Output is correct
4 Correct 13 ms 468 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Execution timed out 3058 ms 2652 KB Time limit exceeded
7 Halted 0 ms 0 KB -