Submission #831733

# Submission time Handle Problem Language Result Execution time Memory
831733 2023-08-20T12:50:38 Z Chal1shkan Preokret (COCI19_preokret) C++14
44 / 50
1 ms 324 KB
//Bismillahir-Rahmanir-Rahim
 
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 1e6 + 7;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void ma1n (/* SABR */) {
	ll n;
	cin >> n;
	ll a[n + 3];
	for (ll i = 1; i <= n; ++i) cin >> a[i];
	ll cnt1 = 0, cnt2 = 0;
	ll ans1 = 1, ans2 = 1;
	for (ll i = 1; i <= n; ++i) {
		if (a[i] == 1) {
			cnt1++;
		}
		if (a[i] == 2) {
			cnt2++;
		}
		ans1 += (cnt1 == cnt2);
		if (cnt1 != cnt2) {
			ll x;
			if (cnt1 < cnt2) {
				x = 1;
			}
			else {
				x = 2;
			}
			ll j = i;
			while (j + 1 <= n && a[j + 1] == x) ++j;
			ans2 = max(ans2, j - i);
		}
	}
	cout << cnt1 << ' ' << cnt2 << nl;
	cout << ans1 << nl << ans2 << nl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test) {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}
 
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist  | BbIWEJI 3A TObOU!!!
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Partially correct 0 ms 212 KB Output is partially correct
8 Correct 0 ms 212 KB Output is correct
9 Partially correct 1 ms 212 KB Output is partially correct
10 Correct 0 ms 212 KB Output is correct