AtCoder Beginner Contest 196

##[A - Difference Max](https://atcoder.jp/contests/abc196/tasks/abc196_a)

O(1)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#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; }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << b - c << endl;

    return 0;
}
```

##[B - Round Down](https://atcoder.jp/contests/abc196/tasks/abc196_b)

O(N)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#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; }

int main() {
    string s;
    cin >> s;

    int p=0;
    rep(i, s.length()) if(s[i] == '.') p = i;

    if(p>0) s.erase(s.begin() + p, s.end());

    cout << s << endl;

    return 0;
}
```

##[C - Doubled](https://atcoder.jp/contests/abc196/tasks/abc196_c)

O(1)

```C++:C++
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i,n) for(ll i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
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; }

int main() {
    string N;
    cin >> N;

    if(N.length() % 2 ==0){
        ll p = N.length() / 2;
        ll start = atoi(N.substr(0, p).c_str());
        ll end = atoi(N.substr(p, N.length()).c_str());

        if(start<=end) cout << start << endl;
        else cout << start - 1 << endl;
    }else{
        string res = "";
        rep(i, (N.length() - 1) / 2) res += "9";
        if(res != "") cout << res << endl;
        else cout << 0 << endl;
    }

    return 0;
}
```

O(N)
こっちの解き方のが正攻法

```C++:C++
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i,n) for(ll i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
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; }

int main() {
    ll N;
    cin >> N;

    ll cnt=0;
    while(stoll((to_string(cnt) + to_string(cnt))) <= N){
        cnt++;
    }
    cout << cnt-1 << endl;

    return 0;
}
```

##[D - Hanjo](https://atcoder.jp/contests/abc196/tasks/abc196_d)

O(HW2^A)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#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; }

int H, W, ans;

void dfs(int n, int bit, int A, int B){
    if(n==H*W){
        ans++;
        return;
    }
    if(bit & 1 << n) return dfs(n + 1, bit, A, B);
    if(B) dfs(n+1, bit | 1<<n, A, B-1);
    if(A){
        if(n%W < W-1 && ~bit&1 << (n+1)) dfs(n+1, bit | 1<<n | 1<<(n+1), A-1, B);
        if(n+W < H*W) dfs(n+1, bit | 1<<n | 1<<(n+W), A-1, B);
    }
}

int main() {
    int A, B;
    cin >> H >> W >> A >> B;

    dfs(0, 0, A, B);

    cout << ans << endl;

    return 0;
}
```

##感想
パフォーマンス509、レートの増減なし。
実力通りの結果。