Submission #376473

# Submission time Handle Problem Language Result Execution time Memory
376473 2021-03-11T14:31:59 Z gustason Rabbit Carrot (LMIO19_triusis) C++14
14 / 100
1000 ms 65500 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
vector<int> ans;
int best = 100;
bool check(vector<int> a) {
    if (a[0] > m) return false;
    for(int i = 1; i < n; i++) {
        if (a[i] - a[i-1] > m) return false;
    }
    return true;
}
void go(int idx, vector<int> a, int changes) {
//    cout << idx << "\n";
    if (idx == n) {
        if (changes < best && check(a)) {
            best = changes;
        } else return;
        ans.resize(n);
        ans = a;
        return;
    }
    int i, k;
    if (idx == 0)
        i = 0;
    else
        i = a[idx-1];
    if (idx == n-1)
        k = 0;
    else
        k = a[idx+1];

    go(idx+1, a, changes);

    a[idx] = i + m;
    go(idx+1, a, changes+1);

    a[idx] = k - m;
    go(idx+1, a, changes+1);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    go(0, a, 0);

    cout << best << "\n";
    for(int i : ans) {
        cerr << i << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 3 ms 364 KB Output is correct
12 Correct 11 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 3 ms 364 KB Output is correct
12 Correct 11 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Execution timed out 1085 ms 65500 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Execution timed out 1085 ms 65500 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Execution timed out 1085 ms 65500 KB Time limit exceeded
5 Halted 0 ms 0 KB -