# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1267822 | minhmc2019 | Rabbit Carrot (LMIO19_triusis) | C++20 | 625 ms | 472 KiB |
#include <bits/stdc++.h>
#define FOR(i, l, r, x) for(int i = l; i <= r; i += x)
#define FOD(i, l, r, x) for(int i = l; i >= r; i -= x)
#define debug(x) cout << "[DEBUG]: " << #x << " = " << x << endl;
#define BIT(x) (1 << (x))
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18;
int n, M, h[N];
inline bool isOn(int mask, int i) {
return ((mask >> i) & 1LL);
}
void solve() {
cin >> n >> M;
FOR(i, 1, n, 1) cin >> h[i];
h[0] = 0;
int ans = 0;
FOR(mask, 0, BIT(n) - 1, 1) {
int last_i = -1;
bool isValid = true;
//
// debug(bitset<5>(mask));
FOR(i, 0, n - 1, 1) {
if (!isOn(mask, i)) continue;
// if (last_i == -1) {
// last_i = i;
// continue;
// }
bool can_move = (h[last_i + 1] + ((i - last_i) * M) >= h[i + 1]);
if (!can_move) {
// cout << "index: " << last_i << " " << i << endl;
// cout << "height: " << h[last_i + 1] << " " << ((i - last_i) * M) << " " << h[i + 1] << endl << endl;
isValid = false;
break;
}
last_i = i;
}
if (isValid) {
ans = max(ans, (int)__builtin_popcountll(mask));
}
}
cout << n - ans << endl;
}
signed main() {
#define name "task"
if (ifstream(name".inp")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |