답안 #527898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527898 2022-02-18T16:40:00 Z 1ne Izbori (COCI22_izbori) C++14
10 / 110
3000 ms 716 KB
#include<iostream>
#include<algorithm>
#include<functional>
#include<numeric>
#include<vector>
#include<utility>
#include<map>
using namespace std;
long long merge(int left,int mid ,int right,vector<int64_t>&arr) {
	vector<int64_t>temp;
	int i = left, j = mid+1;
	long long ans = 0;
	while (i <= mid && j <= right) {
		if (arr[i] <= arr[j]) { 
			temp.push_back(arr[i]);
			++i;
		}
		else {
			temp.push_back(arr[j]);
			++j;
		}
	}
	while (i <= mid) {
		temp.push_back(arr[i]);
		++i;
	}
	while (j <= right) {
		temp.push_back(arr[j]);
		++j;
	}
	for (auto x : temp) {
		arr[left] = x;
		++left;
	}
	return ans;
}
long long mergesort(int left,int right,vector<int64_t>&arr) {
	int mid = (left + right) >> 1;
	if (left >= right)return 0 ;
	long long ans = 0;
	ans+=mergesort(left, mid, arr);
	ans+=mergesort(mid+1, right, arr);
	ans+=merge(left, mid, right, arr);
	return ans;
}
int main() {
	int n;cin >> n;
	vector<int>arr(n);
	for (int i = 0;i < n;++i)cin >> arr[i];
	int64_t ans = n;
	for (int i = 2;i <= n;++i) {
		for (int j = 0;j <= n - i;++j) {
			map<int, int>mp;
			bool ok = false;
			for (int k = j;k < i + j;++k) {
				mp[arr[k]]++;
				if (mp[arr[k]] > i / 2) {
					ok = true;
					break;
				}
			}
			ans += ok;
		}
	}
	cout << ans << '\n';
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 62 ms 264 KB Output is correct
4 Correct 62 ms 272 KB Output is correct
5 Correct 61 ms 264 KB Output is correct
6 Correct 9 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 62 ms 264 KB Output is correct
4 Correct 62 ms 272 KB Output is correct
5 Correct 61 ms 264 KB Output is correct
6 Correct 9 ms 296 KB Output is correct
7 Execution timed out 3058 ms 296 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 62 ms 264 KB Output is correct
4 Correct 62 ms 272 KB Output is correct
5 Correct 61 ms 264 KB Output is correct
6 Correct 9 ms 296 KB Output is correct
7 Execution timed out 3058 ms 296 KB Time limit exceeded
8 Halted 0 ms 0 KB -