This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int INT;
#define int ll
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,pii> piiii;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vector<string>sub={"0","1"};
void dfs(int idx, int n) {
if (idx==n) return;
vector<string>ss;
for (string s:sub) {
s.push_back('0');
ss.push_back(s);
s.pop_back();
s.push_back('1');
ss.push_back(s);
}
sub=ss;
dfs(idx+1,n);
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n,m;
cin >> n >> m;
vector<int>vec(n);
for (int i=0; i<n; i++) {
cin >> vec[i];
}
dfs(1,n);
int mn=LLONG_MAX,cur=0;
for (string s:sub) {
vector<int>temp=vec;
cur=0;
int tot=0;
// always go up by maximum amount (going down always works)
bool b=true;
for (int i=0; i<n; i++) {
if (temp[i]>cur+m) {
if (s[i]=='0') {
b=false;
break;
}
}
if (s[i]=='1') {
temp[i]=cur+m;
tot++;
}
cur=temp[i];
}
if (b) {
mn=min(mn,tot);
}
// cout << s << " " << cur << " " << tot << endl;
}
cout << mn << "\n";
}
/*
*/
| # | 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... |