/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 348.0 KiB
#2 Accepted 13ms 532.0 KiB
#3 Accepted 16ms 536.0 KiB
#4 Accepted 18ms 460.0 KiB
#5 Accepted 25ms 532.0 KiB
#6 Accepted 17ms 1.316 MiB
#7 Accepted 15ms 2.02 MiB
#8 Accepted 18ms 2.02 MiB
#9 Accepted 11ms 532.0 KiB

Code

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

#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n, k, d;
        cin >> n >> k >> d;
        vector<int> v(n);
        for (int i = 0; i < n; i++)
            cin >> v[i];
        int ans = -1, pd = 0, mx = 0;
        int sum = 0, c0 = 0, c1 = 0;
        f(i, k)
        {
            if (v[i] == 0)
                c0++;
            else
                c1++;
            sum += v[i];
        }
        if (sum % d == 0)
        {
            ans = 1;
            if (c0)
                pd = 0;
            else
                pd = 1;
            mx = pd;
        }
        int l = 0, r = k;
        while (r < n)
        {
            if (v[l] == 0)
                c0--;
            else
                c1--;
            sum -= v[l];
            if (v[r] == 0)
                c0++;
            else
                c1++;
            sum += v[r];
            l++;
            r++;
            if (sum % d == 0)
            {
                if (c0)
                    pd = 0;
                else
                    pd = 1;
                if (pd > mx or ans == -1)
                {
                    mx = pd;
                    ans = l + 1;
                }
            }
        }
        cout << ans << endl;
    }
}

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 17:19:05
Judged At
2025-04-06 17:19:05
Judged By
Score
100
Total Time
25ms
Peak Memory
2.02 MiB