답안 #1015895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015895 2024-07-07T03:03:50 Z tuannm Rack (eJOI19_rack) C++17
100 / 100
1 ms 516 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 1e5 + 1;
const string NAME = "";
int n;
long long k;

void addSelf(int &a, int b){
    a += b;
    if(a >= mod[0])
        a -= mod[0];
    if(a < 0)
        a += mod[0];
}

int add(int a, int b){
    a += b;
    if(a >= mod[0])
        a -= mod[0];
    if(a < 0)
        a += mod[0];
    return a;
}

int mul(int a, int b){
    long long a1 = 1LL * a * b;
    long long a2 = (a1 / mod[0]) * mod[0];
    return a1 - a2;
}

void mulSelf(int &a, int b){
    a = mul(a, b);
}

int binpow(int a, int b){
    int ret = 1;
    while(b){
        if(b & 1)
            mulSelf(ret, a);
        mulSelf(a, a);
        b >>= 1;
    }
    return ret;
}

void inp(){
    cin >> n >> k;
}

void solve(){
    int ans = 1;
    for(int i = n - 1; i >= 0; --i){
        if(k & 1)
            k = k + 1 >> 1;
        else{
            addSelf(ans, binpow(2, i));
            k >>= 1;
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

rack.cpp: In function 'void solve()':
rack.cpp:60:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |             k = k + 1 >> 1;
      |                 ~~^~~
rack.cpp: In function 'int main()':
rack.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rack.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct