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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream> using namespace std;
const int N = 1e5 + 10; int q[N]; int res, n;
bool check(int l, int r){ for(int i = l + 1 ; i <= r; i++) for(int j = l; j < i; j++) if(q[j] == q[i]) return false; return true; }
int main(){ scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &q[i]); for(int i = 0; i < n; i++) for(int j = 0; j <= i; j++) if(check(j, i)) res = max(res, i - j + 1); cout<<res; return 0; }
#include <iostream> using namespace std;
const int N = 1e5 + 10; int q[N]; int res, n;
bool check(int l, int r){ for(int j = l; j < r; j++) if(q[j] == q[r]) return 1; return 0; }
int main(){ scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &q[i]); for(int i = 0; i < n; i++){ int j; while(j <= i && check(j,i)) j ++; res = max(res, i - j + 1);
} cout<<res; return 0; }
#include <iostream> using namespace std;
const int N = 1e5 + 10; int n; int a[N],S[N];
int main(){ scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); int res = 0; for(int i = 0, j = 0; i < n; i ++){ S[a[i]] ++; while(S[a[i]] > 1){ S[a[j]] --; j++; } res = max(res, i - j + 1); } cout<<res; return 0; }
|