codeforces 1364A XXXXX 题解 by Ryougi9

题目链接:https://codeforces.com/problemset/problem/1364/A

点击查看代码
#include<iostream>
#include<vector>

using namespace std;

void ryougi9()
{
    int n,x;cin>>n>>x;
    vector<int> v(n+1);
    for(int i=1;i<=n;++i)
    {
        cin>>v[i];
        v[i]%=x;
        v[i]+=v[i-1];
    }
    if(v[n]==0)cout<<-1<<endl;
    else if(v[n]%x)cout<<n<<endl;
    else
    {
        int ans=-1;
        for(int i=1;i<n;++i)
        {
            if(v[i]%x)ans=max(ans,max(i,n-i));
        }
        cout<<ans<<endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin>>t;

    while(t--)ryougi9();

    return 0;
}

作者同步更新:
CSDN
博客园

posted @ 2025-01-24 20:49  Ryougi9  阅读(17)  评论(0)    收藏  举报