AtCoder Beginner Contest 5 questions to fill in tea diff

C - Ubiquity

Python3


n = int(input())
print((10**n-9**n-9**n+8**n)%(10**9+7))

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    ll n;
    cin >> n;
    
    ll mod = 1e9+7;
    ll a=1, b=1, c=1;
    for(ll i=0; i<n; i++){
        a = (a * 10) % mod;
        b = (b * 9) % mod;
        c = (c * 8) % mod;
    }
    ll ans = (a-b-b+c)%mod;
    ans = (ans+mod)%mod;
    cout << ans << endl;
    
    return 0;
}

D - Wandering

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    
    ll ans = 0;
    ll b=0, s=0, max_b=0;
    for(int i=0; i<n; i++){
        b += A[i];
        max_b = max(max_b, b);
        ans = max(ans, s+max_b);
        s += b;
    }
    cout << ans << endl;
    
    return 0;
}

C - Guess The Number

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n, m;
    cin >> n >> m;
    
    string ans;
    rep(i, n) ans += '0';
    
    int A[5]={-1};
    rep(i, m){
        int s, c;
        cin >> s >> c;
        s--;
        if(ans[s] == '0' || ans[s] == c+'0') ans[s] = c + '0';
        else{
            ans = "-1";
            break;
        }
        A[s]=c;
    }
    
    if(ans[0]=='0'){
        if(A[0]==-1 && ans.length()>1) ans[0]='1';
        if(A[0]==0 && ans.length()>1) ans="-1";
    }
    cout << ans << endl;
    
    return 0;
}

C - Typical Stairs

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
int dp[100002];
 
int main(int argc, const char * argv[]) {
    int mod = 1e9+7;
    int N, M;
    cin >> N >> M;
 
    rep(i, N+2) dp[i] = 0;
    rep(i, M){
        int a;
        cin >> a;
        dp[a] = -1;
        if(a>0 && dp[a-1]==-1) { cout << 0 << endl; return 0; }
    }
    
    dp[0]=0;
    if(dp[1]==0) dp[1] = 1;
    if(dp[1]==-1) dp[2] = 1;
    else dp[2] = 2;
    
    for(int i=3; i<=N; i++){
        if(dp[i]==0){
            if(dp[i-1]==-1) dp[i] = dp[i-2];
            else if(dp[i-2]==-1) dp[i] = dp[i-1];
            else dp[i] = (dp[i-1] + dp[i-2]) % mod;
        }
    }
    
    cout << dp[N] << endl;
    
    return 0;
}

C - Dice and Coin

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
 
int main(int argc, const char * argv[]) {
    double N, K;
    cin >> N >> K;
    
    int cc=1;
    double sum=0;
    while(cc<=N){
        int c=cc;
        double cnt=0;
        while(c<K){
            cnt++;
            c=c*2;
        }
        sum += (1.0/N) * pow(1.0/2.0, cnt);
        cc++;
    }
    
    cout << fixed_setprecision(10) << sum << endl;
    
    return 0;
}

C++


#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;


int main(int argc, const char * argv[]) {
    double N, K;
    cin >> N >> K;
    
    int cc=1;
    double sum=0;
    while(cc<=N){
        int c=cc;
        double tmp=1.0/(double)N;
        while(c<K){
            tmp/=2.0;
            c=c*2;
        }
        sum+=tmp;
        cc++;
    }
    
    cout << fixed_setprecision(10) << sum << endl;
    
    return 0;
}

Recommended Posts

AtCoder Beginner Contest 5 questions to fill in tea diff
AtCoder Beginner Contest 066 Review past questions
AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 177
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 179
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 173
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions