Submission

Status:
----PPP---

Score: 30

User: KhunKK9722

Problemset: ไฟส่อง

Language: cpp

Time: 0.001 second

Submitted On: 2025-03-12 08:54:40

#include <stdio.h>
int n;
int a[360] = {};
int tmp1, tmp2;
int ans = 0;
int call = 0;
int maxtmpi = 0;
bool isloop = false;
int light(int pos)
{

    int tmp = 0;
    int tmpi;

    for (int i = pos; i < pos + 360; i++)
    {
        tmpi = i + 1;

        if (tmpi > 360)
            tmpi = i + 1 - 360;
        else
            tmpi = i + 1;
        if (a[tmpi - 1] >= 1 && a[tmpi] >= 1)
        {
            tmp++;
            if (tmpi > maxtmpi)
                maxtmpi = tmpi;
        }
        else if (a[tmpi - 1] >= 1 && a[tmpi] == NULL)
        {
            if (tmp > ans)
                ans = tmp;
        }
        else if (a[tmpi - 1] == NULL && a[tmpi] == 1)
        {
            if (call < 2)
            {
                call++;
                light(tmpi);
            }
        }
        else
        {
            tmp = 0;
        }
    }

    return ans;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &tmp1, &tmp2);
        if (tmp2 < tmp1)
        {
            isloop = true;
            tmp2 += 359;
        }
        for (int x = tmp1 - 1; x < tmp2 + 1; x++)
        {
            if (x >= 360)
            {
                a[x - 360] = 1;
            }
            else
            {
                a[x] = 1;
            }
        }
    }
    light(0);
    if (isloop == false) if(ans>0) ans--;
    if (ans == 0)
        ans = 360;
    printf("%d", ans);
}