AtCoder 生活　23日目

[前回](https://qiita.com/flandrescarlet237/items/6420130da804ba7400b9)

#23日目
今回は、バーチャル参加を3回とC問題を2問解きました

|問題番号|難易度|自力で解けた|かかった時間|
|---|:-:|:-:|---|---|
|ABC140|C|◯|35分20秒|
|ABC141|C|✕|62分49秒|

![スクリーンショット 2020-04-11 22.19.49.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/66fff976-def1-b10d-0d25-0c093f5050bd.png)
![スクリーンショット 2020-04-11 22.23.07.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/61b51122-1c82-d0d6-6088-a7727ce668a5.png)
![スクリーンショット 2020-04-11 22.24.02.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/97ec570e-0240-a8fd-40c5-9c2311cc566b.png)

## [ABC159](https://atcoder.jp/contests/abc159)

###A

```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,m;
    cin >> n >> m;
    int sum = 0;
    sum += n*(n-1)/2;
    sum += m*(m-1)/2;
    cout << sum << 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(){
    string s;
    cin >> s;
    string r = s;
    reverse(r.begin(),r.end());
    if(s != r) {
        cout << "No" << endl;
    }
    s = s.substr(0,s.size()/2);
    string t = s;
    reverse(t.begin(),t.end());
    if(s != t) {
        cout << "No" << endl;
    }
    cout << "Yes" << 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 l;
    cin >> l;
    double s = l/3;
    cout << fixed  << setprecision(8) << pow(s,3) << endl;
}

```

##[ABC160](https://atcoder.jp/contests/abc160)

###A

```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(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << 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 x;
    cin >> x;
    int sum = 0;
    int a = x/500;
    x %= 500;
    int b = x/5;
    cout << a*1000 + b * 5 << 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 k,n;
    cin >> k >> n;
    int m;
    vector<int> a(n+1);
    rep(i,n) cin >> a[i];
    a[n] = k + a[0];
    rep(i,n){
        m = max(m,abs(a[i] - a[i+1]));
    }
    cout << k - m << endl;
}

```

##[ABC161](https://atcoder.jp/contests/abc161)

###A

```c++

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

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z;
}
```

###B


```c++

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

int main(){
    double n,m;
    cin >> n >> m;
    vector<double> a(n);
    rep(i,n) cin >> a[i];
    int sum = 0;
    rep(i,n) sum += a[i];
    int res = 0;
    rep(i,n){
        if(a[i]/sum >= 1/(4*m)){
            res++;
            if(res == m){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

```

###C

```c++

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

int main(){
    ll n,k;
    cin >> n >> k;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll s = n % k;
        ll ans = min(s,abs(s-k));
        cout << ans << endl;
    }
}

```


## ABC140_C

問題:[Maximal Value]
(https://atcoder.jp/contests/abc140/tasks/abc140_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> b(n);
    rep(i,n) cin >> b[i];
    int sum = b[0];
    rep(i,n){
      	if(i != n-2 && b[i] >= b[i+1]) sum += b[i+1];
        else sum += b[i];
    }
    cout << sum << endl;
}

```

解くのにかかった時間：35分20秒
感想：かなり数学的考え方でなんとかなる

## ABC141_C

問題:[Attack Survival]
(https://atcoder.jp/contests/abc141/tasks/abc141_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,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a[i];
    vector<int> cnt(n);
    rep (i,n) cnt[i] = k - q;
    rep(i,q){
        cnt[a[i] - 1]++;
    }
    rep(i,n){
        if(cnt[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

```

解くのにかかった時間：62分49秒
感想：解説を見てｋ-ｑが最低値であることに気づいた

###最後に
明日は、本番でC問題を解きたい