其他分享
首页 > 其他分享> > Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum

Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum

作者:互联网




完整代码如下:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int s[N<<1];

int main() {
    int T; cin>>T;
    while(T--) {
        memset(s, 0, sizeof s);
        int n, k; cin>>n>>k;
        int res = 1e8;
        for(int i = 1; i <= n; i++)
            cin>>a[i];
        for(int i = 1; i <= n/2; i++) {
            int &p = a[i], &q = a[n-i+1];
            if(p > q) swap(p, q);
            s[1] += 2, s[1+p]--, s[q+k+1]++;
        }
        for(int i = 1; i <= 2*k+1; i++)
            s[i] += s[i-1];
        for(int i = 1; i <= n/2; i++) s[a[i] + a[n-i+1]]--;
        for(int i = 1; i <= 2*k; i++)
            res = min(res, s[i]);
        cout<<res<<endl;
    }
}

标签:Palindrome,Constant,636,int,Sum,memset,Codeforces,1e8
来源: https://www.cnblogs.com/tedukuri/p/12756322.html