Submission #68357

# Submission time Handle Problem Language Result Execution time Memory
68357 2018-08-16T19:54:09 Z Bruteforceman Election (BOI18_election) C++11
28 / 100
3000 ms 16180 KB
#include "bits/stdc++.h"
using namespace std;
int a[500010];
int p[500010];

int solve(int l, int r) {
	int cur = 0;
	int ans = 0;
	int mx = 0;
	int mn = 0;
	for(int i = l; i <= r; i++) {
		cur += a[i];
		mn = min(mn, cur);
		mx = max(mx, cur - mn);
	}
	ans += mx - cur;
	cout << mx << ' ' << cur << endl;
	return ans;
}
char s[500010];
int opt[500010];
const int inf = 1e9;
vector <pair <int, int>> g[500010];
int ans[500010];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i = 1; i <= n; i++) {
		a[i] = s[i - 1] == 'C' ? 1 : -1;
	}
	int q;
	scanf("%d", &q);
	int id = 0;
	while(q--) {
		int l, r;
		scanf("%d %d", &l, &r);
		g[l].emplace_back(r, id++);
	}
	fill(opt, opt + n + 1, inf);
	int add = 0;
	for(int i = n; i >= 1; i--) {
		p[i] = -add;
		add += a[i];
		for(int j = i; j <= n; j++) {
			opt[j] = min(opt[j], min(p[i], -add));
		}
		for(auto j : g[i]) {
			int mx = 0;
			for(int k = i; k <= j.first; k++) {
				mx = max(mx, p[k] - opt[k]);
			}
			ans[j.second] = mx - (p[j.first] + add);
		}
	}
	for(int i = 0; i < id; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

Compilation message

election.cpp: In function 'int main(int, const char**)':
election.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
election.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
  ~~~~~^~~~~~~~~
election.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
election.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12152 KB Output is correct
2 Correct 17 ms 12400 KB Output is correct
3 Correct 16 ms 12476 KB Output is correct
4 Correct 17 ms 12476 KB Output is correct
5 Correct 19 ms 12492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12152 KB Output is correct
2 Correct 17 ms 12400 KB Output is correct
3 Correct 16 ms 12476 KB Output is correct
4 Correct 17 ms 12476 KB Output is correct
5 Correct 19 ms 12492 KB Output is correct
6 Execution timed out 3029 ms 16180 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 12152 KB Output is correct
2 Correct 17 ms 12400 KB Output is correct
3 Correct 16 ms 12476 KB Output is correct
4 Correct 17 ms 12476 KB Output is correct
5 Correct 19 ms 12492 KB Output is correct
6 Execution timed out 3029 ms 16180 KB Time limit exceeded
7 Halted 0 ms 0 KB -