CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:N00B.exe
Submission time:2018-10-14 22:24:15 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:42:27: error: no matching function for call to 'std::exception::exception(const char [8])'
  throw exception("Example");
                           ^
In file included from /usr/include/c++/7/exception:38:0,
                 from /usr/include/c++/7/ios:39,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/exception.h:63:5: note: candidate: std::exception::exception()
     exception() _GLIBCXX_USE_NOEXCEPT { }
     ^~~~~~~~~
/usr/include/c++/7/bits/exception.h:63:5: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/7/bits/exception.h:60:9: note: candidate: constexpr std::exception::exception(const std::exception&)
   class exception
         ^~~~~~~~~
/usr/include/c++/7/bits/exception.h:60:9: note:   no known conversion for argument 1 from 'const char [8]' to 'const std::exception&'
input/code.c...

Code

#include <iostream>
#include <stdio.h>
#include <unordered_set>
#include <map>
#include <string>
#define USETI unordered_set<int>
#define CNT(c, val) c.count(val)
#define NSRT(c, val) c.insert(val)
#define PRTI(i) printf("%d", i)
#define PRT(s) printf(s)
#define LBRK printf("\n")
#define PAUSE getchar();getchar()
#define FORS(num, val, n) for(int num = val; num < n; num++)
#define FOR(num, n) for(int num = 0; num < n; num++)
#define SITUATION LBRK; PRT("dNumbers = "); PRTI(dNumbers); LBRK; PRT("Start and end = "); PRTI(start); PRT(" "); PRTI(end); LBRK; PRT("Ans = "); PRTI(ans); LBRK; PAUSE; PAUSE

typedef long long ll;

using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	ll ans = 0;
	scanf("%d %d", &n, &k);

	int* nums = (int*)malloc(4*n);
	USETI nn;

	FOR(i, n)
	{ 
		scanf("%d",(nums + i));
		NSRT(nn, *(nums + i));
		
		//if(nn.size() <= k)
		//{ ans++; }
	}

	throw exception("Example");

	if(nn.size() <= k)
	{
		ll f = n;
		ans = f * ((f + 1) / 2.0);
		printf("%lld", ans);
		free(nums);
		return 0;
	}

	nn.clear();
	map<int, int> m;

	int start = 0;
	int end = -1;
	int* endP = nums + end;
	int* startP = nums + start;
	int dNumbers = 0;

	//ll waste = 0;
	bool wasteFlag = false;
	int endPrev;

	while (dNumbers <= k)
	{
		end++;
		endP++;
		if (m[*endP] == 0)
		{ dNumbers++; }

		//LBRK;
		//PRT("add number "); PRTI(*(nums + end));
		//LBRK;

		m[*endP] += 1;
	}

	ans += (ll)(end - start);

	//SITUATION;

	while (start < n - k)
	{
		//LBRK;
		//PRT("remove number "); PRTI(*(nums + start));
		//LBRK;
		m[*startP] -= 1;
		if (m[*startP] == 0)
		{
			dNumbers--;
			wasteFlag = false;
		}

		start++;
		if (start >= n - k)
		{
			break;
		}
		startP++;

		if(!wasteFlag)
		{
			endPrev = end;
			end++;
			endP++;

			if (end >= n)
			{
				end = n;
				endP = nums + n;
			}

			else
			{
				//LBRK;
				//PRT("add number "); PRTI(*(nums + end));
				//LBRK;
				if (m[*endP] == 0)
				{
					dNumbers++;
				}
				m[*endP] += 1;
			}


			if (dNumbers > k)
			{
				while (end - start >= k + 1)
				{
					//LBRK;
					//PRT("remove number "); PRTI(*(nums + end));
					//LBRK;
					m[*endP] -= 1;
					if (m[*endP] == 0)
					{
						if (dNumbers == k + 1)
						{
							m[*endP] += 1;
							break;
						}
						dNumbers--;
					}
					end--;
					endP--;
					/*
					if (dNumbers <= k)
					{
					end++;
					endP++;
					if (m[*endP] == 0)
					{
					dNumbers++;
					}

					else
					{
					PRT("x"); return 0;
					}

					//LBRK;
					//PRT("add number "); PRTI(*(nums + end));
					//LBRK;

					m[*endP] += 1;
					break;
					}
					*/
				}
			}



			while (dNumbers <= k)
			{
				end++;
				endP++;

				if (end >= n)
				{
					end = n;
					break;
				}

				if (m[*endP] == 0)
				{
					dNumbers++;
				}

				m[*endP] += 1;
			}
		}

		if(!wasteFlag && endPrev == end)
		{ wasteFlag = true; }

		ans += (ll)(end - start);

		//SITUATION;
	}

	ll lk = k;
	ans += lk * ((lk + 1) / 2.0);
	printf("%lld", ans);

	free(nums);
	/*
	LBRK;
	PRT("Wasted move "); printf("%lld", waste);
	PAUSE;
	*/

	return 0;
}