Submission #770990

# Submission time Handle Problem Language Result Execution time Memory
770990 2023-07-02T09:46:10 Z dxz05 Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 340 KB
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx,avx2")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 5005;
 
vector<pair<int, int>> dp[N];
int a[N];
 
void solve(){
    int n, k;
    cin >> n >> k;
 
    for (int i = 1; i <= n; i++) cin >> a[i];
 
    dp[0] = {MP(0, 0)};
 
    for (int i = 1; i <= n; i++){
        vector<int> v;
        for (auto now : dp[i - 1]) v.push_back(now.first + k);
        v.push_back(a[i]);
 
        int j = (int) v.size() - 1;
        while (j > 0 && v[j] < v[j - 1]){
            swap(v[j], v[j - 1]);
            j--;
        }
 
        v.erase(unique(all(v)), v.end());
 
        j = 0;
        for (int h : v){
            while (j < (int) dp[i - 1].size() && dp[i - 1][j].first < h - k) j++;
 
            if (j < (int) dp[i - 1].size()){
                dp[i].emplace_back(h, dp[i - 1][j].second + (a[i] != h));
            }
        }
 
    }
 
    cout << dp[n][0].second << endl;
 
}
 
int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
 
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    int test_cases = 1;
//    cin >> test_cases;
 
    for (int test = 1; test <= test_cases; test++){
        //cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }
 
#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif
 
    return 0;
}

Compilation message

triusis.cpp: In function 'int main()':
triusis.cpp:61:13: warning: unused variable 'startTime' [-Wunused-variable]
   61 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -