CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:tanko
Submission time:2018-10-01 17:54:40 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:20:2: error: 'cin' was not declared in this scope
  cin.tie(NULL);
  ^~~
input/code.cpp:20:2: note: suggested alternative:
In file included from input/code.cpp:1:0:
/usr/include/c++/7/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^~~
input/code.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (sets[i].size() > k) {
        ~~~~~~~~~~~~~~~^~~

Code

#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>

int *table;
bool *elim;
std::set<int> *sets;

int main()
{
	int n, k;
	std::cin >> n >> k;
	table = new int[n];
	elim = new bool[n];
	sets = new std::set<int>[n];
	int ans = 0;

	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for (int i = 0; i < n; ++i) {
		std::cin >> table[i];
	}

	for (int round = 0; round < n; ++round) {
		for (int i = 0; i < n - round; ++i) {
			if (elim[i])
				continue;

			sets[i].insert(table[i + round]);
			if (sets[i].size() > k) {
				elim[i] = true;
			}
		}

		int tmp = ans;
		for (int i = 0; i < n - round; ++i) {
			if (!elim[i])
				++ans;
		}
		if (ans == tmp)
			break;
	}

	std::cout << ans << std::endl;
}