답안 #527897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527897 2022-02-18T16:39:22 Z 1ne Izbori (COCI22_izbori) C++14
0 / 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 0 ms 204 KB Output is correct
2 Correct 2 ms 288 KB Output is correct
3 Incorrect 62 ms 216 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 288 KB Output is correct
3 Incorrect 62 ms 216 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3047 ms 716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 288 KB Output is correct
3 Incorrect 62 ms 216 KB Output isn't correct
4 Halted 0 ms 0 KB -