/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 10ms 540.0 KiB
#3 Accepted 18ms 540.0 KiB
#4 Accepted 15ms 560.0 KiB
#5 Accepted 16ms 540.0 KiB
#6 Accepted 16ms 1.277 MiB
#7 Accepted 18ms 2.25 MiB
#8 Accepted 17ms 2.074 MiB
#9 Accepted 6ms 540.0 KiB

Code

/*
 * Name : Md. Fahmidur Rahman Nafi
 * Date : 2025-04-06   Time : 20:50:15
 */

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define debug(x) cout << "Debug : " << x << endl;
const double PI = 2 * acos(0.0);
const int MOD = 1000000007;

void solve(){
    int n, k, d;
    cin >> n >> k >> d;
    vector <ll> a(n);
    for (auto &i : a) cin >> i;

    ll left = 0, right = 0, sum = 0, pro = 1, zero = 0;
    pair <ll, ll> ans = {LLONG_MIN, LLONG_MIN};

    while (right < n){
        sum += a[right];

        if (a[right] == 0){
            zero++;
            pro = 0;
        }
        else{
            pro *= a[right];
        }

        while (right - left + 1 > k){
            sum -= a[left];

            if (a[left] != 0){
                pro /= a[left];
            }
            else{
                zero--; 
                if (zero == 0){
                    pro = 1; 
                    for (int i = left + 1; i <= right; i++){
                        pro *= a[i];
                    }
                }
            }

            left++;
        }

        if (right - left + 1 == k && sum % d == 0){
            if (ans.first < pro){
                ans.first = pro;
                ans.second = left + 1;
            }
        }
        right++;
    }

    cout << (ans.first == LLONG_MIN ? -1 : ans.second) << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    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:21:56
Judged At
2025-04-06 16:21:56
Judged By
Score
100
Total Time
18ms
Peak Memory
2.25 MiB