Submission #1104088

# Submission time Handle Problem Language Result Execution time Memory
1104088 2024-10-22T17:04:43 Z cot Rack (eJOI19_rack) C++14
100 / 100
8 ms 21072 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define r0 return 0
using namespace std;
const int N = 5 * 1e6 + 5, M = 501, MOD = 998244353, mod = 1e9 + 7;
string s;
int tr[4 * N],a[N],n,m,k,l,q,x,r,tr2[4 * N],b[N];
int bin[N];
void precalc () {
    bin[0] = 1;
    for (int i = 1; i <= 1e6; i++) {
        bin[i] = bin[i - 1] * 2 % mod;
    }
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    precalc();
    cin >> n >> k;
    int i = 0; k = k - 1;
//    cout << k << " " << k % 2 << endl;
    while (k > 0) {
        b[i] = k % 2;
        k = k / 2;
        i++;
    }
    while (i < n - 1) {
        b[i] = 0;
        i++;
    }
//    for (int j = 0; j <= i; j++) {
//        cout << b[j];
//    }
    reverse (b, b + n);
    cout << endl;
    int x = 0;
    for (int i = 0; i <= n - 1; i++) {
        if (b[i] == 0) continue;
        x = (x + bin[i]) % mod;
//        cout <<  x << " " << i << " " << bin[i] << endl;
    }
    cout << x + 1 << endl;
    return 0;
}
// 5 10 ... 10 = 0 1 0 1 0; 9 = 0 1 0 0 1
// b[] = 1 0 0 1 0 => 0 1 0 0 1;
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12880 KB Output is correct
2 Correct 6 ms 12880 KB Output is correct
3 Correct 6 ms 12960 KB Output is correct
4 Correct 6 ms 12880 KB Output is correct
5 Correct 6 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12880 KB Output is correct
2 Correct 6 ms 12880 KB Output is correct
3 Correct 6 ms 12960 KB Output is correct
4 Correct 6 ms 12880 KB Output is correct
5 Correct 6 ms 12880 KB Output is correct
6 Correct 6 ms 12880 KB Output is correct
7 Correct 6 ms 12880 KB Output is correct
8 Correct 6 ms 12880 KB Output is correct
9 Correct 6 ms 12880 KB Output is correct
10 Correct 7 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12880 KB Output is correct
2 Correct 6 ms 12880 KB Output is correct
3 Correct 6 ms 12960 KB Output is correct
4 Correct 6 ms 12880 KB Output is correct
5 Correct 6 ms 12880 KB Output is correct
6 Correct 6 ms 12880 KB Output is correct
7 Correct 6 ms 12880 KB Output is correct
8 Correct 6 ms 12880 KB Output is correct
9 Correct 6 ms 12880 KB Output is correct
10 Correct 7 ms 12880 KB Output is correct
11 Correct 7 ms 12880 KB Output is correct
12 Correct 6 ms 12880 KB Output is correct
13 Correct 7 ms 14928 KB Output is correct
14 Correct 6 ms 14928 KB Output is correct
15 Correct 8 ms 21072 KB Output is correct