Connection Status:
Competition Arena > Submission #15
System Testing
96 / 96
AC 96/96 test cases passed
Submission #15
ProblemNoQuickGrowth
Handlenawa
Submitted2026-07-05 08:17:27
Source Code
#include <vector>
#include <algorithm>

using namespace std;

class NoQuickGrowth {
public:
    int solve(int N, int delta, int spread, int seed) {
        vector<long long> C(N);
        long long state = seed;
        long long mod_val = 1LL << 31; // 2^31
        
        // Generate the sequence A and simultaneously build transformed array C
        for (int i = 0; i < N; ++i) {
            // Pseudorandom generation
            state = (state * 1103515245LL + 12345LL) % mod_val;
            long long diff = state % (2LL * spread + 1);
            long long A_i = 1LL * i * delta + diff - spread;
            
            // Transform the sequence: C[i] = 10*i - A[i]
            C[i] = 10LL * i - A_i;
        }
        
        // Find the length of the Longest Non-Decreasing Subsequence (LNDS) of C
        vector<long long> tails;
        for (int i = 0; i < N; ++i) {
            // upper_bound finds the first element strictly greater than C[i]
            auto it = upper_bound(tails.begin(), tails.end(), C[i]);
            
            if (it == tails.end()) {
                // If C[i] is larger than or equal to all elements, append it
                tails.push_back(C[i]);
            } else {
                // Otherwise, overwrite the first element that is strictly greater
                *it = C[i];
            }
        }
        
        // Minimum shots = total elements - elements we can keep
        return N - tails.size();
    }
};