/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 32ms 39.02 MiB
#2 Accepted 32ms 39.137 MiB
#3 Accepted 32ms 39.008 MiB
#4 Accepted 31ms 38.984 MiB
#5 Accepted 33ms 39.031 MiB
#6 Accepted 32ms 39.09 MiB
#7 Accepted 31ms 39.02 MiB
#8 Accepted 30ms 39.086 MiB
#9 Accepted 33ms 39.039 MiB
#10 Accepted 32ms 38.969 MiB
#11 Accepted 49ms 39.09 MiB
#12 Accepted 33ms 39.086 MiB
#13 Accepted 32ms 38.953 MiB
#14 Accepted 32ms 39.121 MiB
#15 Accepted 33ms 39.004 MiB
#16 Accepted 91ms 39.199 MiB
#17 Accepted 91ms 39.191 MiB
#18 Accepted 674ms 39.52 MiB
#19 Accepted 694ms 39.52 MiB
#20 Accepted 42ms 39.52 MiB
#21 Accepted 784ms 39.52 MiB
#22 Accepted 984ms 39.445 MiB
#23 Accepted 79ms 39.52 MiB
#24 Accepted 40ms 39.316 MiB
#25 Accepted 39ms 39.453 MiB
#26 Accepted 39ms 39.406 MiB

Code

#include <bits/stdc++.h> 
using namespace std;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<ll> vi;
typedef long double ld;
#define ff          first
#define ss          second
#define all(a)      a.begin(),a.end()
#define rall(a)     a.rbegin(),a.rend()
#define pb          push_back
#define mp          make_pair
#define bits(x) __builtin_popcountll(x)
#define endl "\n"
#define M 998244353
#define mod 1000000007
// const long long M = 2e5 + 10, MOD = 2000000007;
// typedef long long ll;
int preix_sum[101][100001];

ll binToDec(string s) { return bitset<64>(s).to_ullong(); }
string decToBin(ll a) { return bitset<64>(a).to_string(); }

void solve() {
 int n, k, x;
        cin >> n >> k >> x;
        vector<int> arr(n + 1);
        for (int i = 1; i <= n; i++) cin >> arr[i];

        memset(preix_sum, 0, sizeof(preix_sum));

        for (int i = 1; i <= n; i++) {
            for (int j = x + 1; j <= 100; j++) {
                if (arr[i] % j == 0) {
                    preix_sum[j][i] = preix_sum[j][i - 1]; // cost saving
                } else {
                    int lagba = j - (arr[i] % j);
                    preix_sum[j][i] = preix_sum[j][i - 1] + lagba; // cost saving
                }
            }
        }

        int res = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = x + 1; j <= 100; j++) {
                int l = i, r = n;
                while (l <= r) {
                    int mid = l + (r - l) / 2;
                    int cur_sum = preix_sum[j][mid] - preix_sum[j][i - 1]; // longest subarray cost check
                    if (cur_sum <= k) {
                        res = max(res, mid - i + 1);
                        l = mid + 1;
                    } else {
                        r = mid - 1;
                    }
                }
            }
        }
        cout << res << "\n";
    
}

int main(){

    auto begin = std::chrono::high_resolution_clock::now();
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll test=1;
    // cin>>test;

    for(int i=1;i<=test;i++) {
        //cout << "Case #" << i << ": ";
        
        solve();
    }
    
	  auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-21 18:56:30
Judged At
2025-02-21 18:56:30
Judged By
Score
100
Total Time
984ms
Peak Memory
39.52 MiB