You are viewing a single comment's thread. Return to all comments →
//Code C++ #include<bits/stdc++.h> #define f(a,b,i) for(int i=a;i<=b;i++) #define ll long long using namespace std; ll largest_product(string s,int k){ int n=s.size(); ll res=-1e18; f(0,n-k+1,i){ ll multi=1; f(i,i+k-1,j){ multi*=(s[j]-48); } res=max(res,multi); } return res; } int main() { int t; cin>>t; while(t--){ int n,k; cin>>n>>k; string res=""; f(1,n,i){ char s; cin>>s; res+=s; } cout<<largest_product(res,k)<<'\n'; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →