답안 #1018970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018970 2024-07-10T11:23:25 Z aeg Izbori (COCI22_izbori) C++17
40 / 110
3000 ms 22572 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 344 KB Output is correct
2 Correct 1 ms 348 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 348 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 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 348 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 23 ms 348 KB Output is correct
11 Correct 17 ms 344 KB Output is correct
12 Correct 23 ms 444 KB Output is correct
13 Correct 14 ms 348 KB Output is correct
14 Correct 13 ms 348 KB Output is correct
15 Correct 14 ms 348 KB Output is correct
16 Correct 21 ms 472 KB Output is correct
17 Correct 13 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2652 KB Output is correct
2 Correct 18 ms 3432 KB Output is correct
3 Correct 21 ms 2132 KB Output is correct
4 Correct 18 ms 3676 KB Output is correct
5 Correct 25 ms 3928 KB Output is correct
6 Correct 21 ms 3920 KB Output is correct
7 Correct 40 ms 3920 KB Output is correct
8 Correct 25 ms 3936 KB Output is correct
9 Correct 20 ms 3860 KB Output is correct
10 Correct 20 ms 3920 KB Output is correct
11 Correct 30 ms 22572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 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 348 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 23 ms 348 KB Output is correct
11 Correct 17 ms 344 KB Output is correct
12 Correct 23 ms 444 KB Output is correct
13 Correct 14 ms 348 KB Output is correct
14 Correct 13 ms 348 KB Output is correct
15 Correct 14 ms 348 KB Output is correct
16 Correct 21 ms 472 KB Output is correct
17 Correct 13 ms 348 KB Output is correct
18 Correct 13 ms 2652 KB Output is correct
19 Correct 18 ms 3432 KB Output is correct
20 Correct 21 ms 2132 KB Output is correct
21 Correct 18 ms 3676 KB Output is correct
22 Correct 25 ms 3928 KB Output is correct
23 Correct 21 ms 3920 KB Output is correct
24 Correct 40 ms 3920 KB Output is correct
25 Correct 25 ms 3936 KB Output is correct
26 Correct 20 ms 3860 KB Output is correct
27 Correct 20 ms 3920 KB Output is correct
28 Correct 30 ms 22572 KB Output is correct
29 Execution timed out 3075 ms 3924 KB Time limit exceeded
30 Halted 0 ms 0 KB -