ABC290参加記

3完10分 2291位

A問題

問題の配点$A_{i}$のうち、$B_{1},B_{2},…B_{M}$問目の合計を取得する。

import std;

void main() {
    int N, M;
    readf("%d %d\n", N, M);

    auto A = readln.chomp.split.to!(int[]);
    auto B = readln.chomp.split.to!(int[]);

    auto res = B.map!(b => A[b-1]).array.sum;
    res.writeln;
}

B問題

答えの文字列$T$の$i$文字目を文字列$S$の$i$文字目がoかつ$i-1$文字目までに含まれるoが$K$未満であればo、そうでなければxと構築する。

import std;

void main() {
    int N, K;
    string S;
    readf("%d %d\n%s\n", N, K, S);

    int cnt;
    auto res = new dchar[](N);
    foreach (i, s; S) {
        if (s == 'o' && cnt < K) res[i] = 'o', ++cnt;
        else res[i] = 'x';
    }

    res.writeln;
}

C問題

$0$から$K-1$まで順に配列$A$に含まれているか確認していき、含まれていない場合その値が答えとなる。 $0$から$K-1$まで含まれている場合、答えは$K$である。

import std;

void main() {
    int N, K;
    readf("%d %d\n", N, K);

    auto A = readln.chomp.split.to!(int[]);

    auto G = A.dup.sort.group.array;

    int res, num, cnt;
    foreach (g; G) {
        if (g[0] == num) {
            ++num, ++cnt;
            res = max(res, num);
        }

        if (cnt == K) break;
    }

    res.writeln;
}