Submission #759339

# Submission time Handle Problem Language Result Execution time Memory
759339 2023-06-16T08:01:26 Z gvancak Election (BOI18_election) C++11
28 / 100
3000 ms 26144 KB
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
using namespace std;
ll n,k,a[1000005],b[1000005],dp[1000005],ans[1000005],mx,l,z,x,q,r;
map <ll,ll> m;
vector <ll> v[1000005];
string s;
bool ok;
int main()
{
    cin>>n;
    cin>>s;
    for (int i=0; i<s.size(); i++)
    if (s[i]=='C') a[i+1]=1;
    else a[i+1]=-1;
    for (int i=1; i<=n; i++) b[i]=a[i];
    //prefix da sufix a[i]>=0 gvinda
    cin>>q;
    for (int o=1; o<=q; o++){
        cin>>l>>r;
        x=0; k=0;
        for (int i=l; i<=r; i++){
            x+=b[i];
            if (x<0){
                b[i]=0; k++; x=0;
            }
        }
        x=0;
        for (int i=r; i>=l; i--){
            x+=b[i];
            if (x<0){
                b[i]=0; k++; x=0;
            }
        }
        cout<<k<<endl;
        for (int i=1; i<=n; i++) b[i]=a[i];
    }
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<s.size(); i++)
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 17 ms 23764 KB Output is correct
3 Correct 18 ms 23848 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 22 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 17 ms 23764 KB Output is correct
3 Correct 18 ms 23848 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 22 ms 23764 KB Output is correct
6 Execution timed out 3064 ms 26144 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 17 ms 23764 KB Output is correct
3 Correct 18 ms 23848 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 22 ms 23764 KB Output is correct
6 Execution timed out 3064 ms 26144 KB Time limit exceeded
7 Halted 0 ms 0 KB -