AtCoder Beginner Contest 240

## [A - Edge Checker](https://atcoder.jp/contests/abc240/tasks/abc240_a)

O(1)
a=1とb=１０の時だけ分岐します。


```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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;
    cin >> a >> b;

    if(a==1 && b==10){
        cout << "Yes" << endl;
        return 0;
    }

    if(b-a==1){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
} 
```

## [B - Count Distinct Integers](https://atcoder.jp/contests/abc240/tasks/abc240_b)

O(N)
連想配列か、setでカウントしましょう。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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 N;
    cin >> N;

    map<int, int> mp;
    rep(i, N){
        int a;
        cin >> a;
        mp[a]++;
    }
    cout << mp.size() << endl;

    return 0;
} 
```

## [C - Jumping Takahashi](https://atcoder.jp/contests/abc240/tasks/abc240_c)

O(100*10000)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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; }
 
bool dp[101][10010];
 
int main() {
    int N, X;
    cin >> N >> X;

    vector<int> A(N), B(N);
    rep(i, N){
        int a, b;
        cin >> a >> b;
        A[i] = a;
        B[i] = b;
    }

    dp[0][0] = 1;
    rep(i, N){
        rep(j, X){
            if (dp[i][j]) {
                if(j+A[i] <= X){
                    dp[i+1][j+A[i]] = true;
                }
                if(j+B[i] <= X){
                    dp[i+1][j+B[i]] = true;
                }
            }
        }
    }

    if(dp[N][X]) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}
```

## [D - Strange Balls](https://atcoder.jp/contests/abc240/tasks/abc240_d)

O(N)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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 N;
    cin >> N;

    stack<vector<int>> st;
    int ans=0;
    rep(i, N){
        int a;
        cin >> a;

        if(st.size()>0 && st.top()[0]==a){
            st.top().push_back(a);
            ans++;
            if(st.top().size() == a){
                ans -= st.top().size();
                st.pop();
            }
        }else{
            st.push(vector<int>(1, a));
            ans++;
        }
        
        cout << ans << endl;
    }

    return 0;
} 
```