Submission #902064

# Submission time Handle Problem Language Result Execution time Memory
902064 2024-01-10T05:50:21 Z Isam Izbori (COCI22_izbori) C++17
25 / 110
3000 ms 2532 KB
#include<bits/stdc++.h>
using namespace std;

int N, A[200005];
long long pref[200005];


signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for(register int i = 1; i <= N; ++i) cin >> A[i];
	
	if(N < 200005){
		int cur_dom(0), ans(0);
		for(int i = 1; i <= N; ++i){
			map<int, int> mp;
			for(register int j = i; j <= N; ++j){
				mp[A[j]]++;
				if(mp[A[j]] > mp[cur_dom]) cur_dom = A[j];
				ans += (mp[cur_dom] > ((j - i + 1) / 2));
			}
		}
		cout << ans << '\n';	
    }else{
    	for(register int i = 1; i <= N; ++i) A[i] = (A[i] == 1 ? 1 : -1), pref[i] = pref[i - 1] + A[i];
    	map<int, int> mp;
    	long long ans(0);
    	for(register int i = 1; i <= N; ++i){
    		mp[pref[i]]++;
    		ans += mp[pref[i]];
		}
    	cout << ans << '\n';
	}
	return 0;
}
/*

1 1 2 1 2

-1 -1 1 -1 1


abs(pref[r] - pref[l]) >= 1;

pref[r] != pref[l]

ans = n * (n + 1) / 2 - regular_brackets





*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |  for(register int i = 1; i <= N; ++i) cin >> A[i];
      |                   ^
Main.cpp:17:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   17 |    for(register int j = i; j <= N; ++j){
      |                     ^
Main.cpp:25:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |      for(register int i = 1; i <= N; ++i) A[i] = (A[i] == 1 ? 1 : -1), pref[i] = pref[i - 1] + A[i];
      |                       ^
Main.cpp:28:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   28 |      for(register int i = 1; i <= N; ++i){
      |                       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 70 ms 2532 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 61 ms 2396 KB Output is correct
10 Correct 61 ms 2488 KB Output is correct
11 Correct 65 ms 2396 KB Output is correct
12 Correct 59 ms 2396 KB Output is correct
13 Correct 60 ms 2496 KB Output is correct
14 Correct 62 ms 2488 KB Output is correct
15 Correct 65 ms 2492 KB Output is correct
16 Correct 64 ms 2492 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 70 ms 2532 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 61 ms 2396 KB Output is correct
10 Correct 61 ms 2488 KB Output is correct
11 Correct 65 ms 2396 KB Output is correct
12 Correct 59 ms 2396 KB Output is correct
13 Correct 60 ms 2496 KB Output is correct
14 Correct 62 ms 2488 KB Output is correct
15 Correct 65 ms 2492 KB Output is correct
16 Correct 64 ms 2492 KB Output is correct
17 Correct 11 ms 2396 KB Output is correct
18 Execution timed out 3062 ms 2396 KB Time limit exceeded
19 Halted 0 ms 0 KB -