Submission #642608

# Submission time Handle Problem Language Result Execution time Memory
642608 2022-09-20T08:45:08 Z NewChapter Rack (eJOI19_rack) C++14
20 / 100
1 ms 320 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define forn(i, s, n) for(int i = s; i < n; ++i)
#define forj(j, s, n) for(int j = s; j < n; ++j)
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const char* fileNameIn = "main.in";
const char* fileNameOut = "main.out";
#define files() freopen(fileNameIn, "r", stdin); freopen(fileNameOut, "w", stdout)
 
const int N = 2e5;
const int M = N + 7;
const int INF = 1e9;
typedef long long ll;

ll binpow(ll base, ll power) {
	if(power == 1) {
		return base;
	}
	if(power == 0) {
		return 1;
	}
	if(power % 2 == 0) {
		ll tmp = binpow(base, power >> 1);
		return tmp * tmp % M;
	}
	else {
		ll tmp = binpow(base, (power - 1) >> 1);
		return tmp * tmp % M * base % M;
	}
}

int main() {
	fast_io;
	int n;
	ll k;
	ll ans = 0;
	cin >> n >> k;
	string k_bin = "";
	k -= 1;
	while(k) {
		k_bin = to_string(k % 2) + k_bin;
		k /= 2;
	}
	while(k_bin.size() != n) {
		k_bin = "0" + k_bin;
	}
	forn(i, 0, k_bin.size()) {
		ans += binpow(2, i) * (k_bin[i] - '0');
		ans %= M;
	}
	ans += 1;
	cout << ans;
}

Compilation message

rack.cpp: In function 'int main()':
rack.cpp:53:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |  while(k_bin.size() != n) {
      |        ~~~~~~~~~~~~~^~~~
rack.cpp:11:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define forn(i, s, n) for(int i = s; i < n; ++i)
......
   56 |  forn(i, 0, k_bin.size()) {
      |       ~~~~~~~~~~~~~~~~~~                
rack.cpp:56:2: note: in expansion of macro 'forn'
   56 |  forn(i, 0, k_bin.size()) {
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -