首页 > 代码库 > Codeforces Round #245 (Div. 2) B - Balls Game

Codeforces Round #245 (Div. 2) B - Balls Game

暴利搜索即可

#include <iostream>#include <vector>#include <iostream>using namespace std;int main(){    int n,k,x;    cin >> n >> k >> x;    vector<int> c(n);    for(int i = 0 ; i < n; ++ i) cin >> c[i];    int ans = 0;    for(int i = 1; i < n ; ++ i){        if(c[i] == x && c[i] == c[i-1]){            int left = i-1, right = i,s=0,flag = 1;            while(true){                int left_cnt = 0, right_cnt = 0,j,k;                for(j = left; j >= 0 && c[j] == c[left]; -- j) left_cnt++;                for(k = right; k < n && c[k] == c[right]; ++ k) right_cnt++;                if(left_cnt+right_cnt + flag >= 3 && c[left] == c[right]){                    left = j;right =k;                    s+=left_cnt+right_cnt;                    flag = 0;                 }else{                    ans = max(ans,s);break;                }            }        }            }    cout<<ans<<endl;}