Submission #796763

#TimeUsernameProblemLanguageResultExecution timeMemory
796763nirmalgRabbit Carrot (LMIO19_triusis)C++14
0 / 100
1 ms212 KiB
#include "bits/stdc++.h" using namespace std; // Template modified from https://usaco.guide/general/generic-code?lang=cpp#templates #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; using vll = vector<ll>; using vpii = vector<pii>; using vvi = vector<vi>; using vvll = vector<vll>; using vvpii = vector<vpii>; #define Sum(v) (accumulate(v.begin(), v.end(), 0ll)) #define Sort(v) (sort(v.begin(), v.end())) constexpr ll INF = 1e9; constexpr int MOD = 998244353; // #define IO(NAME) \ // cin.tie(0)->sync_with_stdio(0); \ // if(fopen(NAME ".in","r")) freopen(NAME ".in","r",stdin), \ // freopen(NAME ".out","w",stdout); template <typename T1, typename T2> // cin >> pair<T1, T2> istream &operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); } template <typename T> // cin >> vector<T> istream &operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } template <typename T1, typename T2> // cout << pair<T1, T2> ostream &operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); } template <typename T> // cout << vector<T> ostream &operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } // bitwise ops // j is 0 based indexing // __builtin_ctzll() for long long and __ builtin_popcount() #define LSB(S) ((S) & -(S)) ll LCM(int a, int b) { return ((ll)a * b) / __gcd(a, b); } bool nCr_Parity(int n, int r){ int i = 0; while(i <= 30){ // for 32 bit integers int x = 1<<i; if((x&r) > (x&n)) return 0; ++i; } return 1; // 1 is odd } int memo[10], a[10], n, m; int dp(int i, int h, bool changed){ if(i == n - 1) return changed; if(changed){ if(a[i + 1] - h > m){ return 1 + dp(i + 1, h + m, 1); } else{ return 1 + dp(i + 1, a[i + 1], 0); } } else{ if(a[i + 1] - h > m){ int ans1 = 1 + dp(i + 1, a[i + 1], 0); int ans2 = dp(i + 1, h + m, 1); return min(ans1, ans2); } else{ return dp(i + 1, a[i + 1], 0); } } } void solve(){ cin >> n >> m; for(int i = 0; i < n; ++i){ cin >> a[i]; } bool ch = 0; if(a[0] > m){ ch = 1; a[0] = m; } int ans = dp(0, a[0], ch); cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(10) << fixed; // IO(""); solve(); } // when using printf, scanf for long long use %dll // when using accumulate use 0ll if sum is long long

Compilation message (stderr)

triusis.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | // #define IO(NAME) \
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...