답안 #288639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288639 2020-09-01T17:31:29 Z Benmath Rack (eJOI19_rack) C++14
40 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
long long int solve(long long int step[],long long int b,long long int n,long long int mod){
 
    long long int step1=1;
    long long int x,y;
long long int b11=b;
    long long int b1;

    if(b11%2==0){
        y=(b11-2)/2;
    }else{
        y=(b11-1)/2;
    }
    if(b11==1){
        return 1;
    }
   
    if(b11==2){ 
        return step[n-1]+1;
    }

    int mi=0;

    for(int i=1;i<=n;i++){
        if(i!=1){
            step1*=2;
            mi++;
        }
        if((y-step1)<step1 and (y-step1)>=0){
            b1=y-step1;
        break;
    }
    }

 b1=b1%mod;
 

    if(b11%2==0){
        return ( solve(step,b1+1,mi+1,mod)*step[n-2-mi]+step[n-1]+1)%mod;
    }else{
 
        return (solve(step,b1+1,mi+1,mod)*step[n-2-mi]+1)%mod;
    }
}
int main(){
    int n;
    cin>>n;
    long long int k;
    cin>>k;
    long long int mod=1000000007;
    k=k%mod;
    long long int step[n+1];
    step[0]=1;
    for(int i=1;i<=n;i++){
        step[i]=(step[i-1]*2)%mod;
    }
 if(k==1){
     cout<<1;
 }else if(k==2){
     cout<<step[n-1]+1;
 }else{
     long long int k1;

        cout<<solve(step,k,n,mod);
 }

}

Compilation message

rack.cpp: In function 'long long int solve(long long int*, long long int, long long int, long long int)':
rack.cpp:6:19: warning: unused variable 'x' [-Wunused-variable]
    6 |     long long int x,y;
      |                   ^
rack.cpp: In function 'int main()':
rack.cpp:63:20: warning: unused variable 'k1' [-Wunused-variable]
   63 |      long long int k1;
      |                    ^~
rack.cpp: In function 'long long int solve(long long int*, long long int, long long int, long long int)':
rack.cpp:36:4: warning: 'b1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |  b1=b1%mod;
      |  ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Incorrect 0 ms 256 KB Output isn't correct
13 Halted 0 ms 0 KB -