General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
95378891 Practice:
tmaddy
1208B - 39 C++17 (GCC 7-32) Time limit exceeded on test 29 2000 ms 752 KB 2020-10-13 00:19:45 2020-10-13 00:19:45
→ Source
#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> a;

// 7 5 4 9

bool check(int len) {

	for(int i=0; i<=n-len; ++i) {
		// to exclude [i, i + len - 1]
		unordered_set<int> s;
		for(int j=0; j<n; ++j) {
			if(j < i || j > i + len - 1) {
				s.insert(a[j]);
			}
		}
		if(s.size() == n - len) {
			return true;
		}
	}

	return false;

}

void solve() {

	cin >> n;
	a.resize(n);

	for(int i=0; i<n; ++i)
		cin >> a[i];


	unordered_set<int> s;

	for(int x: a) s.insert(x);

	if(s.size() == n) {
		cout << 0;
		return;
	}

	int b = 0;
	int g = n;


	while(g > b + 1) {
		int mid = (g + b) / 2;
		if(check(mid))
			g = mid;
		else 
			b = mid;
	}

	cout << g;


}

int main() {

	solve();

	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details