# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
937852 | sleepntsheep | Election (BOI18_election) | C11 | 5 ms | 2396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
int lo(int a, int b)
{
return a<b?a:b;
}
int hi(int a, int b)
{
return a>b?a:b;
}
#define N 500000
int n, q;
char s[N+1];
int go[N],bk[N];
int f(char c)
{
return c == 'C' ? 1 : -1;
}
int main()
{
scanf("%d%s%d", &n, s, &q);
go[0] = f(s[0]);
bk[n-1] = f(s[n-1]);
for (int i = 1; i < n; ++i) go[i] = go[i-1] + f(s[i]);
for (int i = n - 2; i >= 0; --i) bk[i] = bk[i+1] + f(s[i]);
for (int x, y, i = 0; i < q; ++i)
{
scanf("%d%d", &x, &y);
--y; --x;
int c = 0, L = 0, R = 0;
for (int i = x; i <= y; ++i)
if (s[i] == 'C')
++c;
else
{
if (!c) ++L;
else --c;
}
c = 0;
for (int i = y; i >= x; --i)
if (s[i] == 'C')
++c;
else
{
if (!c) ++R;
else --c;
}
int z = hi(L, R);
printf("%d\n", z);
}
}
컴파일 시 표준 에러 (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... |