/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 9ms 536.0 KiB
#3 Wrong Answer 15ms 576.0 KiB

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 sum=0, zero=0;

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

    ll mx=-1, ans= -1;

    if(sum%d == 0){
        ll p= (zero == 0)? 1: 0;
        if(p > mx){
            mx= p;
            ans= 0;
        }
    }

    fl(i , k , n){
        sum -= a[i-k];
        if(a[k-i]==0)zero--;

        sum += a[i];
        if(a[i]==0)zero++;

        if(sum%d == 0){
            ll p= (zero == 0)? 1: 0;
            if(p > mx){
                mx= p;
                ans= i - k + 1;
            }
        }
    }

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


int main(){
    InShaAllah

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

Information

Submit By
Type
Submission
Problem
P1190 Segment Strength
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-07 04:32:03
Judged At
2025-04-07 04:32:03
Judged By
Score
0
Total Time
15ms
Peak Memory
576.0 KiB