输入上万的题目 用scanf不要用cin。 我写的也是暴力O(n^2),AC了
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;
class Solution{
public:
int getKMul(vector<int>& v, int k){
int sum;
int mxlen = 0;
for (int i=0; i<v.size(); i++) {
sum = 0;
for (int j=i; j<v.size(); j++) {
sum += v[j];
if (sum % k == 0) {
mxlen = max(j-i+1, mxlen);
}
}
if (mxlen >= v.size()-i) {
break;
}
}
return mxlen;
}
};
int main(){
int n;
cin>>n;
vector<int> v;
int x;
for (int i=0; i<n; i++) {
scanf("%d",&x);
v.push_back(x);
}
int k;
cin>>k;
Solution s;
cout<<s.getKMul(v, k)<<endl;
}