Submission #170419

# Submission time Handle Problem Language Result Execution time Memory
170419 2019-12-25T06:54:23 Z Retro3014 Election (BOI18_election) C++17
28 / 100
3000 ms 1432 KB
#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 500000;

int N;
string str;
int Q;
bool chk[MAX_N+1];

int main(){
	cin>>N>>str>>Q;
	for(int i=0; i<Q; i++){
		int a, b;
		scanf("%d%d", &a, &b); a--; b--;
		for(int j=0; j<N; j++)	chk[j] = false;
		int ans = 0, c = 0;
		for(int j=a; j<=b; j++){
			if(c==0 && str[j]=='T'){
				ans++; chk[j] = true;
			}else{
				if(str[j]=='T'){
					c--;
				}else{
					c++;
				}
			}
		}
		c = 0;
		for(int j=b; j>=a; j--){
			if(chk[j])	continue;
			if(c==0 && str[j]=='T'){
				ans++;
			}else{
				if(str[j]=='T')	c--;
				else	c++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b); a--; b--;
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 376 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 9 ms 376 KB Output is correct
5 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 376 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 9 ms 376 KB Output is correct
5 Correct 8 ms 376 KB Output is correct
6 Execution timed out 3037 ms 1432 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 376 KB Output is correct
3 Correct 8 ms 376 KB Output is correct
4 Correct 9 ms 376 KB Output is correct
5 Correct 8 ms 376 KB Output is correct
6 Execution timed out 3037 ms 1432 KB Time limit exceeded
7 Halted 0 ms 0 KB -