Submission #66952159


Source Code Expand

#include<bits/stdc++.h>
#define int long long

const int inf = 1e9;


using namespace std;
int n , q;

bool IsBlack(int ind , vector<int>&arr)
{
	if(ind < 0 || ind >= n)
		return false;
	
	if(arr[ind] == 1)
		return true;
	
	return false;
}

bool IsWhite(int ind , vector<int>&arr)
{
	if(ind < 0 || ind >= n)
		return true;
	
	if(arr[ind] == 0)
		return true;
	
	return false;
}


int32_t main(void)
{
	
	
	cin >> n >> q;
	
	vector<int> arr(n , 0); // 0 -> white
	
	int ans = 0;
	
	while(q--)
	{
		int ind;
		cin >> ind;
		
		ind--;
		
		if(arr[ind] == 0)
		{
			arr[ind] = 1;
			if(!(IsBlack(ind - 1 , arr) || IsBlack(ind + 1 , arr)))
				ans++;
			
			else if(IsBlack(ind - 1 , arr) && IsBlack(ind + 1 , arr))
				ans--;
			
		}
		else
		{
			arr[ind] = 0;
			
			if(IsWhite(ind - 1, arr) && IsWhite(ind + 1, arr))
				ans--;
			else if(IsBlack(ind - 1 , arr) && IsBlack(ind + 1 , arr))
				ans++;
			
			
			
		}
		
		
		cout << ans << "\n";
		
		
	}
	
	
	return 0;
}

Submission Info

Submission Time
Task C - Black Intervals
User Sarthak_Borse
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1050 Byte
Status AC
Exec Time 624 ms
Memory 7576 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 29
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 11 ms 3400 KiB
example_01.txt AC 1 ms 3644 KiB
example_02.txt AC 1 ms 3420 KiB
hand_00.txt AC 581 ms 7112 KiB
hand_01.txt AC 571 ms 7060 KiB
hand_02.txt AC 580 ms 7576 KiB
hand_03.txt AC 535 ms 7100 KiB
hand_04.txt AC 1 ms 3456 KiB
hand_05.txt AC 534 ms 3352 KiB
random_00.txt AC 575 ms 3600 KiB
random_01.txt AC 573 ms 7060 KiB
random_02.txt AC 617 ms 5392 KiB
random_03.txt AC 623 ms 3464 KiB
random_04.txt AC 565 ms 3660 KiB
random_05.txt AC 565 ms 3472 KiB
random_06.txt AC 580 ms 3556 KiB
random_07.txt AC 574 ms 3560 KiB
random_08.txt AC 596 ms 4908 KiB
random_09.txt AC 588 ms 5940 KiB
random_10.txt AC 582 ms 3676 KiB
random_11.txt AC 567 ms 3488 KiB
random_12.txt AC 617 ms 5152 KiB
random_13.txt AC 576 ms 3356 KiB
random_14.txt AC 582 ms 3688 KiB
random_15.txt AC 568 ms 3592 KiB
random_16.txt AC 566 ms 3564 KiB
random_17.txt AC 624 ms 5336 KiB
random_18.txt AC 556 ms 3464 KiB
random_19.txt AC 574 ms 3460 KiB