/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 14ms 592.0 KiB
#3 Wrong Answer 32ms 636.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long int
#define N "\n"
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)
    {
        ll n,k,d;
        cin>>n>>k>>d;
        vector<ll>a(n);
        vector<pair<ll,ll>>val;
        for(ll i=0;i<n;i++)cin>>a[i];

        ll sum=0,p=1;
        map<ll,ll>mp;

        for(ll i=0;i<n;i++){

            if(i<k){
                  sum+=a[i];
                  mp[a[i]]++;
                  if(i==k-1){
                        if(sum%d==0){
                              if(mp[0]){
                                    val.push_back({0,0});
                              }
                              else{
                                    val.push_back({1,0});
                              }
                        }
                        
                  }
                  continue;
            }
                  mp[i-k]--;
                  sum-=a[i-k];
                  sum+=a[i];
                  mp[a[i]]++;
                  if(sum%d==0){
                        if(mp[0]){
                              val.push_back({0,i-k+1});
                        }
                        else{
                              val.push_back({1,i-k+1});
                        }
                  }
      }
        ll mx=0,mn=1e9;
        for(auto i:val){
            if(i.first>=mx){
                  mx=i.first;
                  mn=i.second;
            }
        }
        if(mn==1e9){
            cout<<-1<<N;
        }
        else{
            cout<<mn+1<<N;
        }
    }
}

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 15:57:23
Judged At
2025-04-06 15:57:23
Judged By
Score
0
Total Time
32ms
Peak Memory
636.0 KiB