/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 488.0 KiB
#2 Accepted 1ms 396.0 KiB
#3 Wrong Answer 1ms 320.0 KiB
#4 Wrong Answer 1ms 368.0 KiB

Code

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

int main(){
  /*int t;
  cin >> t;
  while (t--){*/
    ll n, k, x, c = 0, g = 0, mx = 0;
    cin >> n >> k >> x;
    x += 1;
    ll mx2 = 0;
    vector<ll> a(n), pre(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
      mx2 = max(mx2, a[i]);
    }
    for (ll i = x; i * i <= mx2; i++){
c=0,g=0;
      for (int j = 0; j < n; j++){
        g = __gcd(a[j], g);
        if (g >= i){
          c++;
          mx = max(mx, c);
        } else {
          c = 0;
          g = a[j];
          if (g >= i){
            c++;
            mx = max(mx, c);
          }
        }
      }
    }
    ll l = 0, r = 0, f = 0;
    while (r < n){
      if (a[r] % x == 0){
        if (f == 0){
          while (l < r){
            k += pre[l];
            pre[l] = 0;
            l++;
          }
          f = 1;
        }
        mx = max(mx, r - l + 1);//cout<<r<<' '<<l<<endl;
        r++;//cout<<mx<<' ';
      } else if (x - (a[r] % x) <= k){
        if (f == 0){
          while (l < r){
            k += pre[l];
            pre[l] = 0;
            l++;
          }
          f = 1;
        }
        pre[r] += (x - (a[r] % x));
        k -= (x - (a[r] % x));//cout<<r<<' '<<l<<endl;
        mx = max(mx, r - l + 1);
        r++;//cout<<mx<<' ';
      } else {
        f = 0;
        k += pre[l];
        pre[l] = 0;
        l++;
      }//cout<<mx<<' ';
      if (l > r) r++;
    }
    cout << mx << endl;
  //}
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Contest
TLE_Headquarters - round #1
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-27 17:51:35
Judged At
2024-11-11 03:37:23
Judged By
Score
1
Total Time
1ms
Peak Memory
488.0 KiB