-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30804.cpp
More file actions
35 lines (30 loc) · 730 Bytes
/
30804.cpp
File metadata and controls
35 lines (30 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
#define FastIO\
ios_base::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
using namespace std;
int main(){
FastIO;
int n;
cin>>n;
deque<int> arr(n+1);
for(int i=1; i<=n; i++){
cin>>arr[i];
}
int left=1;
int max_length=0;
map<int,int> kind;
for(int right=1; right<=n; right++){//오른쪽으로 한칸식
kind[arr[right]]++;
while(kind.size()>2){//종류가 2개가 넘어가면
kind[arr[left]]--;
if(kind[arr[left]]==0){
kind.erase(arr[left]);
}
left++;
}
max_length=max(max_length, right-left+1);
}
cout<<max_length;
}