AtCoder Beginner Contest 216

##[A - Signed Difficulty](https://atcoder.jp/contests/abc216/tasks/abc216_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() {
    double d;
    cin >> d;

    int x = d;
    int y = (d - x)*10;

    if(0<= y && y <= 2) cout << x << "-" << endl;
    else if (3<= y && y <= 6) cout << x << endl;
    else cout << x << "+" << endl;

    return 0;
}
```

##[B - Same Name](https://atcoder.jp/contests/abc216/tasks/abc216_b)

O(N^2)

```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 N;
    cin >> N;

    vector<pair<string, string>> ST(N);
    rep(i, N){
        cin >> ST[i].first >> ST[i].second;
    }

    int ok=0;
    rep(i, N){
        for(int j=i+1; j<N; j++){
            if(ST[i].first == ST[j].first && ST[i].second == ST[j].second) ok=1;
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
```

##[C - Many Balls](https://atcoder.jp/contests/abc216/tasks/abc216_c)

O(N)
制約として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() {
    ll N;
    cin >> N;

    string res;
    while(N>0){

        if(N%2==0){
            res = "B" + res;
            N/=2;               
        }else{
            res = "A" + res;
            N--;
        }
    }

    cout << res << endl;

    return 0;
}
```

##[D - Pair of Balls](https://atcoder.jp/contests/abc216/tasks/abc216_d)

O(N+M)
queueとデータ構造で解く問題。
queueは気づいたけど、色をkeyにiを保持するのを思いつきませんでした。

```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 N, M;
    cin >> N >> M;

    vector<queue<int>> A(M);
    vector<vector<int>> mem(N);
    queue<int> que;
    rep(i, M){
        int k;
        cin >> k;

        rep(j, k){
            int a;
            cin >> a;
            A[i].push(a-1);
        }
        mem[A[i].front()].push_back(i);
    }

    rep(i, N){
        if(mem[i].size() == 2){
            que.push(i);
        }
    }

    while(que.size()>0){
        int now = que.front();
        que.pop();

        for(auto &v:mem[now]){
            A[v].pop();
            if(!A[v].empty()){
                mem[A[v].front()].push_back(v);
                if(mem[A[v].front()].size() == 2){
                    que.push(A[v].front());
                }
            } 
        }
    }

    for(auto &v:A){
        if(!v.empty()){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;

    return 0;
}
```