답안 #1018655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018655 2024-07-10T07:54:37 Z vjudge1 Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 22376 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define int int64_t

random_device rd;
mt19937_64 rng(rd.entropy() != 0 ? rd() : chrono::high_resolution_clock::now().time_since_epoch().count());

constexpr long double PI = 3.14159265358979323846264; // PI 23 decimal digit
struct chash {
	static constexpr int64_t C = int64_t(2e18 * PI) + 23;
	const int64_t RANDOM = rng();
	template <typename T, enable_if_t<is_integral<T>::value, bool> = true>
	inline size_t operator()(T const& x) const {
		return __builtin_bswap64((int64_t(x)^RANDOM)*C);
	}
};

template <typename T1, typename T2> using cmap = __gnu_pbds::gp_hash_table<T1, T2, chash>;

int32_t main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &x:a) cin >> x;
	if(*max_element(a.begin(), a.end()) <= 2) {
		for(int i = 0; i < n; i ++) if(a[i] == 2) a[i] = -1;
		vector<int> pref(n);
		pref[0] = a[0];
		for(int i = 1; i < n; i ++) pref[i] = a[i] + pref[i - 1];
		cmap<int, int> s;
		s[0] ++;
		int ans = 0;
		for(int i = 0; i < n; i ++) {
			ans += i + 1 - s[pref[i]];
			s[pref[i]] ++;
		}
		cout << ans << '\n';
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i ++) {
		cmap<int, int> m;
		int curmax = 0;
		for(int j = i; j < n; j ++) {
			m[a[j]]++;
			curmax = max(curmax, m[a[j]]);
			if(curmax > (j - i + 1) / 2) ans++;
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 20 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 472 KB Output is correct
10 Correct 14 ms 472 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 14 ms 468 KB Output is correct
13 Correct 16 ms 344 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 14 ms 344 KB Output is correct
16 Correct 14 ms 348 KB Output is correct
17 Correct 11 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2652 KB Output is correct
2 Correct 17 ms 3460 KB Output is correct
3 Correct 10 ms 2240 KB Output is correct
4 Correct 25 ms 3508 KB Output is correct
5 Correct 18 ms 3676 KB Output is correct
6 Correct 20 ms 4116 KB Output is correct
7 Correct 19 ms 3932 KB Output is correct
8 Correct 23 ms 4032 KB Output is correct
9 Correct 19 ms 3940 KB Output is correct
10 Correct 19 ms 3944 KB Output is correct
11 Correct 29 ms 22376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 20 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 472 KB Output is correct
10 Correct 14 ms 472 KB Output is correct
11 Correct 14 ms 348 KB Output is correct
12 Correct 14 ms 468 KB Output is correct
13 Correct 16 ms 344 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 14 ms 344 KB Output is correct
16 Correct 14 ms 348 KB Output is correct
17 Correct 11 ms 472 KB Output is correct
18 Correct 13 ms 2652 KB Output is correct
19 Correct 17 ms 3460 KB Output is correct
20 Correct 10 ms 2240 KB Output is correct
21 Correct 25 ms 3508 KB Output is correct
22 Correct 18 ms 3676 KB Output is correct
23 Correct 20 ms 4116 KB Output is correct
24 Correct 19 ms 3932 KB Output is correct
25 Correct 23 ms 4032 KB Output is correct
26 Correct 19 ms 3940 KB Output is correct
27 Correct 19 ms 3944 KB Output is correct
28 Correct 29 ms 22376 KB Output is correct
29 Execution timed out 3056 ms 3780 KB Time limit exceeded
30 Halted 0 ms 0 KB -