AT_abc032_c [ABC032C] 列
思路
首先题目给出的是连续的子序列,所以可以直接用双指针进行维护,定义一个变量,如果这个变量乘上 那么指针的右端点就往右移就可以了,最后窗口的变量要除以掉 进行滑动指针。要特判一下其中一个 是零的情况,直接输出 就可以了。
Code
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
int a[N],ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n,k;cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>a[i];
if (a[i]==0){
cout<<n<<endl;
return 0;
}
}
int l=1,r=0;
int res=1;
while (l<n){
while (r<n && res*a[r+1]<=k) r++,res*=a[r];
ans=max(ans,r-l+1);
if (l<=r) res/=a[l];
l++;
}
cout<<ans<<endl;
return 0;
}
通过记录:https://atcoder.jp/contests/abc032/submissions/68990116