# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
68357 | Bruteforceman | Election (BOI18_election) | C++11 | 3029 ms | 16180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |