Submission #1096925

#TimeUsernameProblemLanguageResultExecution timeMemory
1096925nguyen31hoang08minh2003Rack (eJOI19_rack)C++17
100 / 100
10 ms11824 KiB
#include <set> #include <map> #include <cmath> #include <queue> #include <deque> #include <stack> #include <math.h> #include <bitset> #include <vector> #include <string> #include <cstdio> #include <cctype> #include <numeric> #include <fstream> #include <sstream> #include <cstdlib> #include <iomanip> #include <cassert> #include <cstring> #include <stdio.h> #include <string.h> #include <iterator> #include <iostream> #include <algorithm> #include <strings.h> #include <functional> #include <unordered_set> #include <unordered_map> #define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i) #define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i) #define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i) #define fi first #define se second #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;}; template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;}; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; constexpr int MAX_N = 1E6 + 6, MOD = 1E9 + 7; const ll INF = 0X3F3F3F3F3F3F3F3F; signed result, p[MAX_N]; ll k, r[MAX_N]; int n; /* Idea: At a node, if the weights of two children branches are equal than go to left branch Otherwise go to right branch Observation: At i-th level there is power(2, i - 1) direct branches from the immediately above level and every branch of these branches will be visited before any branch is visited again This means that, there will be power(2, i - 1) times of choosing the left child branch then power(2, i - 1) times of choosing the right child branch then again ... (continue the cycle) */ signed main() { #ifdef LOCAL freopen("input.INP", "r", stdin); // freopen("output.OUT", "w", stdout); #endif // LOCAL cin.tie(0) -> sync_with_stdio(0); cout.tie(0); cin >> n >> k; p[0] = r[0] = 1; fort(i, 1, n) { p[i] = (p[i - 1] << 1) % MOD; r[i] = min(r[i - 1] << 1, INF); } for (int i = n - 1, j = 0; i >= 0; --i, ++j) if (((k - 1) / r[j]) & 1) (result += p[i]) %= MOD; (++result) %= MOD; cout << result << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...