Submission #1068789

# Submission time Handle Problem Language Result Execution time Memory
1068789 2024-08-21T12:09:49 Z PotatoTheWarriorFRTT Global Warming (CEOI18_glo) C++14
10 / 100
2000 ms 3560 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
ll p1 = 27644437;
ll p2 = 1000000007;
 
int LIS(int n, ll a[]) {
    ll dp[n+1]; // dp[l] = smallest element at which a sequence of size l ends;
    int ans = 1;
    dp[1] = a[0];
    for(int i=1;i<n;i++) {
        if(dp[ans] < a[i]) {
            ans++;
            dp[ans] = a[i];
        }else if(a[i] < dp[1]) {
            dp[1] = a[i];
        }else{
            int r = ans;
            int l = 1;
            while(r - l > 1) {
                int m = (r+l)/2;
                if(a[i] < dp[m]) {
                    r = m;
                }else if(a[i] >= dp[m]) {
                    l = m;
                }
            }
            dp[r] = a[i]; 
        }
    }
    return ans;
}

void solve() {
    int n, x; cin >> n >> x;
    ll a[n+1];

    for(int i=0;i<n;i++) {
        cin >> a[i];
    }
    if(x == 0) {
        cout << LIS(n, a) << endl;
    }else{
        int ans = 0;
        for(int i=0;i<n;i++) {
            for(int j=i;j<n;j++) {
                for(int d=-x;d<=x;d++) {
                    for(int k=i;k<=j;k++) {
                        a[k]+=d;
                    }
                    ans = max(ans, LIS(n, a));
                    for(int k=i;k<=j;k++) {
                        a[k]-=d;
                    }
                }
            }
        }
        cout << ans << endl;
    }
 
}
int main()   {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // int t; cin >> t;
    // while(t--) 
        solve();
 
    char dksfjn;
    cin >> dksfjn;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3556 KB Output is correct
2 Correct 22 ms 3396 KB Output is correct
3 Correct 20 ms 3560 KB Output is correct
4 Correct 21 ms 3552 KB Output is correct
5 Correct 19 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2077 ms 1100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2041 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -