답안 #376476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376476 2021-03-11T14:33:30 Z gustason Rabbit Carrot (LMIO19_triusis) C++14
14 / 100
1000 ms 65400 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;
}

Compilation message

triusis.cpp: In function 'void go(int, std::vector<int>, int)':
triusis.cpp:24:12: warning: variable 'k' set but not used [-Wunused-but-set-variable]
   24 |     int i, k;
      |            ^
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Execution timed out 1104 ms 65400 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Execution timed out 1104 ms 65400 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Execution timed out 1104 ms 65400 KB Time limit exceeded
5 Halted 0 ms 0 KB -