답안 #937858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937858 2024-03-04T15:36:57 Z sleepntsheep Election (BOI18_election) C
0 / 100
6 ms 2396 KB
#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;
        int at[4000]={0},m=0;
        for (int i = x; i <= y; ++i)
            if (s[i] == 'C')
                ++c;
            else
            {
                if (!c) ++L, at[m++] = i;
                else --c;
            }

        int tot = 0;
        for (int i = at[0]; i <= y; ++i) tot += (s[i] == 'T');

        c = 0;
        for (int i = y; i >= x; --i)
        {
            if (s[i] == 'C') ++c;
            else
            {
                if (i >= at[0])
                {
                    if (m > 0 && tot && i == at[m-1])
                    {
                        --m;
                        ++R;
                        --tot;
                    }
                    else
                        if (tot > m) ++R, --tot;
                }
                else
                {
                    if (c) --c;
                    else ++R;
                }
            }
        }

        int z = hi(L, R);
        printf("%d\n", z);
    }
}

Compilation message

election.c: In function 'main':
election.c:27:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%s%d", &n, s, &q);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
election.c:34:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d%d", &x, &y);
      |         ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -