AtCoder 生活　27日目

[前回](https://qiita.com/flandrescarlet237/items/fb80f9bbff929713feb0)
#27日目
今回は、バーチャル参加を3回しました

![スクリーンショット 2020-04-15 16.55.15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/c5793ca4-62eb-f336-050d-5d4dade1521c.png)
![スクリーンショット 2020-04-15 20.08.58.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/e631432f-004b-7882-98eb-f4bb7a10450b.png)
![スクリーンショット 2020-04-15 23.10.04.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/65ae1434-bbb9-07d0-9f61-071a6a23ec07.png)

##[ABC135](https://atcoder.jp/contests/abc135)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    ll a,b;
    cin >> a >> b;
    if((a+b)%2 != 0) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
}

```

###B


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n){
        cin >> p[i];
        q[i] = p[i];
    }
    int res = 0;
    sort(q.rbegin(),q.rend());
    rep(i,n){
        if(p[i] != q[i]) res++;
    }
    if(res <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

```

###C


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n+1) cin >> a[i];
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        int num = min(a[i],b[i]);
        ans += num;
        b[i] -= num;
        int num2 = min(a[i+1],b[i]);
        ans += num2;
        a[i+1] -= num2;
    }
    cout << ans << endl;
}

```

##[ABC136](https://atcoder.jp/contests/abc136)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max((b+c)-a,0) << endl;
}

```

###B


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 1;i <= (n);i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    int res = 0;
    rep(i,n){
        string s = to_string(i);
        if (s.size()%2 != 0) res++; 
    }
    cout << res << endl;
}

```

###C


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0;i < (n);i++)
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }
    bool ans = 1;
    for(ll i = n-1;i>0;i--){
        if(h[i] == h[i-1]-1) h[i-1]--;
        else if(h[i] < h[i-1] -1){
            ans = 0;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

```


##[ABC137](https://atcoder.jp/contests/abc137)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    int a,b;
    cin >> a >> b;
    cout << max({a+b,a-b,a*b})  << endl;
}

```

###B


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;

int main(){
    int k,x;
    cin >> k >> x;
  	if(k == 1){
    	cout << x << endl;
      	return 0;
    }
    for(int i = k-1;i > 0;i--) cout << x - i << " " ;
    cout << x << " ";
    for(int i = 1;i < k;i++) cout << x + i << " ";
}

```

###C


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;

int main(){
    ll n;
    ll res = 0;
    cin >> n;
    vector<string> s(n);
  	unordered_map<string,ll> um(n);
    rep(i,n) {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    rep(i,n){
    	um[s[i]] += 1;
      	res += um[s[i]] -1;
    }
    cout << res << endl;
}

```

感想:unordered_mapというものをはじめて知った。

##最後に
今回、かなり計算量をどのようなアプローチで行けばよいのかの判断力不足を感じた。少しずつ、しかし着実に実力をつけたい。