#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
const int N=200005;
const long long INF = LLONG_MAX;
const int INF2=(int)1e18;
const int LOG=20;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
typedef priority_queue<pii,vector<pii>,greater<pii>> min_pq;
typedef priority_queue<pii> max_pq;
typedef long long ll;
//sunlari dusun//
/*
* kodu kisaltcak fonksiyon
* cevaba binary search ya da normal bs
* segment tree / sparse table
* stack
* teklik ciftlik
* precomputation
* EN ONEMLISI OVERKILLEME
* edge case dusun
* constraintlere bak
* indisleri kontrol et
* dp
* greedy
* sorting
* dfs bfs
* sieve
*/
void solve()
{
int n;
cin >> n;
int arr[n+1];
for(int i=1;i<=n;i++) cin >> arr[i];
int cnt1=0,cnt2=0;
for(int i=1;i<=n;i++) (arr[i]==1 ? cnt1++ : cnt2++);
cout << cnt1 << " " << cnt2 << endl;
int cnt3=1,cur1=0,cur2=0;
pii anlik[n+1];
anlik[0]={0,0};
for(int i=1;i<=n;i++)
{
if(arr[i]==1) cur1++;
else cur2++;
if(cur1==cur2) cnt3++;
anlik[i]={cur1,cur2};
}
cout << cnt3 << endl;
int last[n+1];
last[0]=0;last[1]=1;
for(int i=2;i<=n;i++)
{
if(arr[i]==arr[i-1]) last[i]=last[i-1]+1;
else last[i]=1;
}
int cnt4=0;
for(int i=1;i<=n;i++)
{
pii lt=anlik[i-last[i]];
if(arr[i]==1)
{if(anlik[i].ff>anlik[i].ss && lt.ff<lt.ss) cnt4=max(cnt4,last[i]);}
else
{if(anlik[i].ss>anlik[i].ff && lt.ss<lt.ff) cnt4=max(cnt4,last[i]);}
}
cout << cnt4 << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
cout << fixed << setprecision(15);
int t=1;//cin>> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |