/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 344.0 KiB
#2 Accepted 10ms 532.0 KiB
#3 Accepted 43ms 532.0 KiB
#4 Accepted 42ms 352.0 KiB
#5 Accepted 113ms 532.0 KiB
#6 Time Exceeded ≥1099ms ≥1.062 MiB
#7 Accepted 130ms 2.02 MiB
#8 Time Exceeded ≥1001ms ≥2.02 MiB

Code

/* 
*   @author:- SYEDA SADIATUL JANNAT TUSHI
*   date & time :2025-03-17 02:32:27
*   BANGLADESH , SYLHET. 
*/

#include <bits/stdc++.h>
using namespace std;

#define endl          '\n'
#define ll            long long
#define vi            vector<ll>
#define pii           pair<ll,ll>
#define vii           vector<pii>
#define sz(x)         (int)x.size()
#define be(x)         x.begin(), x.end()
#define srt(v)         sort(v.begin(),v.end())
#define rsrt(v)        sort(v.rbegin(),v.rend())
#define fl(i, a, b)   for(ll i = (a); i < (b); i++)
#define print(v)      for(auto e:v) cout<<e<<" "; cout<<endl;
#define InShaAllah    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


void solve(){
   ll n, k ,d;
   cin >> n >> k >> d;

   vi a(n);
   fl(i, 0 ,n)cin >> a[i];

   ll mx=-1, start=-1, sum=0, product=1;

   fl(i, 0 , k){
    sum += a[i];
    product *= a[i];
   }

   if(sum %d ==0){
    mx= product;
    start= 0;
   }

   fl(i, k, n){
    ll left= i-k;

    sum -= a[left];
    sum += a[i];

    if( a[left] == 0){
        product = 0;
    }
    product *= a[i];

    if (product == 0) {
       product = 1;
       for (int j = left + 1; j <= i; ++j) {
            product *= a[j];
        }
    }

    if (sum % d== 0 ) {
        if (product > mx) {
             mx = product;
             start = left + 1;
        } else if (product == mx) {
            if (start == -1 || left + 1 <start) {
                start = left + 1;
            }
        }
    }

   } 

   if(start==-1){
    cout<< -1 <<endl;
   }
   else{
    cout << start+1 <<endl;
   }


}

int main(){
    InShaAllah

    ll t=1; cin >> t;
    while (t--)
    {
        solve();
    }
    
}

Information

Submit By
Type
Submission
Problem
P1190 Segment Strength
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 16:49:48
Judged At
2025-04-06 16:49:48
Judged By
Score
50
Total Time
≥1099ms
Peak Memory
≥2.02 MiB