Submission
Status:
----PPP---
Score: 30
User: KhunKK9722
Problemset: ไฟส่อง
Language: cpp
Time: 0.001 second
Submitted On: 2025-03-10 12:11:54
#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;
// printf("\nConsidering %d : i = %d and i+1 = %d",i,a[tmpi-1],a[tmpi]);
if (a[tmpi - 1] >= 1 && a[tmpi] >= 1)
{
tmp++;
if (tmpi > maxtmpi)
maxtmpi = tmpi;
// printf("\tstreak = %d", tmp);
}
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 < 3)
{
call++;
// printf("\ncall = %d\n", call);
// printf("call func\n\n");
light(tmpi);
}
}
else
{
tmp = 0;
// printf("position a[%d] reset streak\n", i);
}
}
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;
// printf("x is %d, set a[%d] to 1\n", x, x - 360);
}
else
{
a[x] = 1;
// printf("x is %d, set a[%d] to 1\n", x, x);
}
}
}
light(0);
// for(int i = 0; i < 360; i++){
// printf("position %d is %d\n",i,a[i]);
// }
// printf("\n\nmaxtmpi is %d",maxtmpi);
if (isloop == false)
ans--;
if(isloop&&ans==0) ans = 360;
printf("%d", ans);
}