AtCoder Beginner Contest 176

##[A - Takoyaki](https://atcoder.jp/contests/abc176/tasks/abc176_a)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
int main(int argc, const char * argv[]) {
    
    int N, X, T;
    cin >> N >> X >> T;
    
    int A = N / X;
    int B = N % X;
    if(B > 0) A++;
    
    cout << A * T << endl;
    
    return 0;
}
```

##[B - Multiple of 9](https://atcoder.jp/contests/abc176/tasks/abc176_b)

- 問題の制約は10^2000000
- ５秒ほどC++とPythonで迷って文字列のLengthの限界値が分からない為、Pythonを選択。

```Python:Python
N = input()
 
Ans = 0
for i in range(0, len(N)):
    Ans += int(N[i])
    Ans = Ans % 9
 
if Ans % 9 == 0:
  print('Yes')
else:
  print('No')
```

##[C - Step](https://atcoder.jp/contests/abc176/tasks/abc176_c)

- 問題の制約は1≤Ai≤10^9
- 誤るとしたら型の最大値と判断してPython使用

```Python:Python
N = int(input())
A = list(map(int, input().split()))
 
TOP = A[0]
Ans = 0
 
for i in range(1, len(A)):
    if TOP > A[i]:
        Ans += TOP - A[i]
    else:
        TOP = A[i]
print(Ans)
```

##[D - Wizard in Maze](https://atcoder.jp/contests/abc176/tasks/abc176_d)

- 悩むのが5*5のゾーンをどうするか
- 配列で直接に全指定。考えるより手で書いた方が早い。

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
int dx[24] =
{1, 0, -1, 0, -2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
int dy[24] =
{0, 1, 0, -1, -2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};
 
int main(int argc, const char * argv[]) {
    
    int H, W;
    int CH, CW;
    int DH, DW;
    char S[1000][1000];
    int COST[1000][1000];
    
    cin >> H >> W;
    cin >> CH >> CW;
    cin >> DH >> DW;
    
    CH--;CW--;DH--;DW--;
    
    for(int h=0; h<H; h++){
        string s;
        cin >> s;
        
        for(int w=0; w<W; w++){
            S[h][w] = s[w];
            COST[h][w] = -1;
        }
    }
    
 
    deque<P> que;
    que.push_front(P(CH, CW));
    COST[CH][CW] = 0;
    
    while(que.size()){
 
        P p = que.front();
        que.pop_front();
 
        for(int i=0; i<4; i++){
 
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            
            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] <= COST[p.first][p.second] && COST[ny][nx] > -1) continue;

            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second];
                que.push_front(P(ny, nx));
            }
        }
        
        for(int i=4; i<24; i++){
 
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            
            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] > -1) continue;
 
            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second] + 1;
                que.push_back(P(ny, nx));
            }
        }
    }
    
    cout << COST[DH][DW] << endl;
    
    return 0;
}
```