Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- //speed coding
- #define mp make_pair
- #define cve(a) for (auto i : a) {cout << i << " "; } cout << "\n";
- #define f first
- #define s second
- #define loop(x, n) for (int i = x; i < n; i++)
- #define joop(x, n) for (ll j = x; j < n; j++)
- #define err cout << "ERROR" << endl;
- #define all(x) x.begin(), x.end()
- #define pb push_back
- #define sz(x) x.size()
- // types
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define vvi vector<vector<int>>
- #define vvll vector<vector<ll>>
- typedef long long ll;
- // types of data
- #define inf 1000000000
- #define infll 1000000000000000000
- #define mod 1000000007
- //#define DEBUG 1
- using namespace std;
- ll n;
- // (a, b, c) -> (a-1, b, c) / 2 ...
- // (a, b, c) -> (a, b-1, c) +1 / 2 ...
- // (a, b, c) -> (a, b, c-1) -1 / 2 ...
- map<tuple<int,int,int>, ll> mem;
- ll f(int a, int b, int c){
- if(mem.count({a,b,c})) return mem[{a,b,c}];
- if(a == 0 and b == 0 and c == 0){
- return n;
- }
- //cout << a << ' ' << b << ' ' << c << " " << res << endl;
- ll res = 1e18;
- if(a > 0) res = min(res, f(a-1,b,c)/2);
- if(b > 0) res = min(res, (f(a,b-1,c)+1)/2);
- if(c > 0) res = min(res, (f(a,b,c-1)-1)/2);
- return mem[{a,b,c}] = res;
- }
- void solve(){
- ll a, b, c;
- cin >> n >> a >> b >> c;
- cout << f(a, b, c);
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- #ifdef DEBUG
- freopen("text.txt", "r", stdin);
- #else
- #endif
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment