Submission #962510

#TimeUsernameProblemLanguageResultExecution timeMemory
962510penguin133Rack (eJOI19_rack)C++17
100 / 100
1 ms452 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
int exp(int a, int b){
	int res = 1;
	while(b){
		if(b & 1)res *= a, res %= mod;
		a *= a, a %= mod;
		b >>= 1;
	}
	return res;
}

void solve(){
	int n, k; cin >> n >> k;
	int cur = 1, tot = 1;
	bool f = 0;
	if(n <= 62 && k > (1ll << (n - 1))){
		f = 1;
		k -= (1ll << (n - 1));
	}
	for(int i = 1; i < n; i++){
		//check if k <= 1ll << (n - i - 1)
		int val = n - i - 1;
		if(val > 62 || (1ll << val) >= k){
			continue;
		}
		else k -= (1ll << val), tot += exp(2, i), tot %= mod;
	}
	cout << tot + f;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message (stderr)

rack.cpp: In function 'void solve()':
rack.cpp:27:6: warning: unused variable 'cur' [-Wunused-variable]
   27 |  int cur = 1, tot = 1;
      |      ^~~
rack.cpp: At global scope:
rack.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...