AtCoder Beginner Contest 258

## [A - When?](https://atcoder.jp/contests/abc258/tasks/abc258_a)

O(1)
21+(K/60)
K%60
そして0パディング。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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 K;
    cin >> K;
    int start = 21;

    int HH = (21 + (K / 60)) % 24;
    int MM = K % 60;

    cout << std::setfill('0') << std::right << std::setw(2) << HH;
    cout << ':';
    cout << std::setfill('0') << std::right << std::setw(2) << MM << endl;

    return 0;
} 
```

## [B - Number Box](https://atcoder.jp/contests/abc258/tasks/abc258_b)

最初に8方向を決める。
愚直にN回ほどindexを遷移させる。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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; }

ll N;
ll A[11][11];
ll ANS=0;

void dfs(ll i, ll j, ll x, ll y, ll cnt, ll sum){

    if(cnt>=N){
        ANS = max(ANS, sum);
        return;
    }

    ll p=1;
    rep(i, N-cnt-1) p*=10;

    sum += A[i][j] * p;
    i += x;
    j += y;

    if(i<0) i = N-1;
    if(i>=N) i = 0;
    if(j<0) j = N-1;
    if(j>=N) j = 0;

    dfs(i, j, x, y, cnt+1, sum);
}

int main() {

    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    rep(i, N){
        rep(j, S.size()){
            A[i][j] = S[i][j] - '0';
        }      
    }


    rep(i, N){
        rep(j, N){
            dfs(i, j, -1, -1, 0, 0);
            dfs(i, j, 0, -1, 0, 0);
            dfs(i, j, 1, -1, 0, 0);
            dfs(i, j, -1, 0, 0, 0);
            dfs(i, j, 1, 0, 0, 0);
            dfs(i, j, -1, 1, 0, 0);
            dfs(i, j, 0, 1, 0, 0);
            dfs(i, j, 1, 1, 0, 0);
        }
    }

    cout << ANS << endl;

    return 0;
} 
```

## [C - Rotation](https://atcoder.jp/contests/abc258/tasks/abc258_c)

貪欲。
t==1の時、-xをsumに加算。
t==2の時、index=sum%N+x。
indexが0以下ならindex += N。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    ll add=0;
    rep(i, Q){
        ll t, x;
        cin >> t >> x;

        if(t==1){
            add -= x;
        }else if(t==2){
            ll d = (add) % N;
            ll index = d + x;
            if(index<1) index += N;
            cout << S[index-1] << endl;
        }
    }

    return 0;
} 
```

## [D - Trophy](https://atcoder.jp/contests/abc258/tasks/abc258_d)

貪欲。
sum = A[i] + B[i]
X -= i+1
sum += B(0~iまでの中で最小の要素) * X

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; 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, X;
    cin >> N >> X;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    
    ll ans = 2e18;
    ll add = 0;
    ll min_b = 2e18;
    rep(i, N){
        ll sum = 0;
        ll xx = X;
        sum = A[i] + B[i] + add;
        xx -= i+1;
        min_b = min(min_b, B[i]);
        sum += min_b * xx;
        ans = min(ans, sum);
        add += A[i] + B[i];
    }
    cout << ans << endl;

    return 0;
} 
```