답안 #466234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466234 2021-08-18T11:31:04 Z Stickfish Rack (eJOI19_rack) C++17
100 / 100
1 ms 204 KB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

ll pw(ll a, ll m){
	if(!m)
		return 1;
	a %= MOD;
	if(m % 2)
		return (a * pw(a, m - 1)) % MOD;
	return pw(a * a, m / 2);
}

signed main(){
	ll n, k;
	cin >> n >> k;
	--k;
	ll ans = 0;
	ll r2 = pw(2, MOD - 2);
	ll pw2 = pw(2, n - 1);
	for(ll i = 0; i < min(n, 63ll); ++i){
		if(k & (1ll << i)){
			ans += pw2;
			ans %= MOD;
		}
		pw2 = (pw2 * r2) % MOD;
	}
	cout << ans + 1 << endl;
	//if(n <= 20){
		//vector<ll> a = {1};
		//for(int sz = 1, pw = (1 << (n - 1)); sz <= k; sz *= 2, pw /= 2){
			//for(int i = 0; i < sz; ++i){
				//a.push_back(a[i] + pw);	
			//}
		//}
		//cout << a[k] << endl;
	//}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct