AtCoder Beginner Contest 219

##[A - AtCoder Quiz 2](https://atcoder.jp/contests/abc219/tasks/abc219_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() {
    int x;
    cin >> x;

    if(x < 40) cout << 40 - x << endl;
    else if(x < 70) cout << 70 - x << endl;
    else if(x < 90) cout << 90 - x << endl;
    else if(x >= 90) cout << "expert" << endl;
    
    return 0;
}
```

##[B - Maritozzo](https://atcoder.jp/contests/abc219/tasks/abc219_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 s1, s2, s3, t;
    cin >> s1 >> s2 >> s3 >> t;

    rep(i, t.size()){
        if(t[i] == '1') cout << s1;
        if(t[i] == '2') cout << s2;
        if(t[i] == '3') cout << s3;
    }
    cout << endl;
    
    return 0;
}
```

##[C - Neo-lexicographic Ordering](https://atcoder.jp/contests/abc219/tasks/abc219_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; }
 
vector<int> pos(26);

int main() {
    string x;
    int N;
    cin >> x >> N;

    rep(i, 26){
        int index = x[i] - 'a';
        pos[index] = i;
    }
 
    vector<string> S(N);
    rep(i, N) cin >> S[i];
 
    sort(S.begin(), S.end(), [](const string& x, const string& y){
        int len = min(x.size(), y.size());
        for(int i=0; i<len; i++){
            if(x[i] != y[i]){
                int index_x = x[i] - 'a';
                int index_y = y[i] - 'a';
                return pos[index_x] < pos[index_y];
            }
        }
        return x.size() < y.size();
    });
 
    rep(i, N) cout << S[i] << endl;
    
    return 0;
}
```

pythonで回答しようとしたコード。
アルファベットを空白を含む２７進数として記載。

```python:python
import sys
import math
import heapq
import itertools
from collections import deque
from functools import reduce

# main
def main():
    x = ' ' + str(input())
    N = int(input())

    S = []
    for i in range(0, N):
        s = str(input())
        res=0
        for j in range(0, len(s)):
            res = res + pow(27, 10-1-j) * (x.index(s[j]))
        S.append((res, s))

    S.sort()

    for key, value in S:
        print(value)
    
# エントリポイント
if __name__ == '__main__':
    main()
```