AtCoder Beginner Contest 229

##[A - First Grid](https://atcoder.jp/contests/abc229/tasks/abc229_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() {
    string s1, s2;
    cin >> s1 >> s2;

    if(s1[0] == s1[1] || s1[0] == s2[0] || s2[1] == s2[0] || s2[1] == s1[1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
```

##[B - Hard Calculation](https://atcoder.jp/contests/abc229/tasks/abc229_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 A, B;
    cin >> A >> B;
 
    int n = min(A.length(), B.length());
 
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
 
    rep(i, n){
        int a = A[i] - '0';
        int b = B[i] - '0';
 
        if(a + b>9){
            cout << "Hard" << endl;
            return 0;
        }
    }
    cout << "Easy" << endl;
 
    return 0;
}
```

##[C - Cheese](https://atcoder.jp/contests/abc229/tasks/abc229_c)

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() {
    int N, W;
    cin >> N >> W;
 
    vector<P> V(N);
    rep(i, N){
        int a, b;
        cin >> a >> b;
        V[i].first = a;
        V[i].second = b;
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
 
    ll res=0;
    ll cnt=0;
    rep(i, N){
        int m = V[i].second;
        rep(j, m){
            res += V[i].first;
            cnt++;
            if(cnt>=W) break;
        }
        if(cnt>=W) break;
    }
    cout << res << endl;
 
    return 0;
}
```

##[D - Longest X](https://atcoder.jp/contests/abc229/tasks/abc229_d)

O(N)
キューに文字を追加します。
'.'が任意の数以上なら先頭からpopします。
キューの最大値が解答です。

```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;
    int K;
    cin >> S >> K;
 
    int N = S.length();
    int cnt=0;
    int res=0;
    queue<char> que;
    rep(i, N){
        que.push(S[i]);
        if(S[i] == '.') cnt++;
        if(cnt>K){
            char c = que.front();
            que.pop();
            if(c == '.') cnt--;
        }
        res = max(res, (int)que.size());
    }
    cout << res << endl;
 
    return 0;
}
```