1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoder Beginner Contest 331 振り返り

Posted at

ABC331

概要

A - Tomorrow

考えてたこと
基本的に、月を跨ぐ際、年を跨ぐ際さえ考えれば良さそうっていう方針で実装したらAC。

提出したもの

a.cpp
int main() {
    int max_m, max_d, y, m, d;
    cin >> max_m >> max_d >> y >> m >> d;

    d++;
    if (d > max_d) {
        m++;
        d = 1;

        if (m > max_m) {
            y++;
            m = 1;
        }
    }

    cout << y << " " << m << " " << d;
    return 0;
}

振り返り
特になし。

B - Buy One Carton of Milk

考えてたこと
最初は卵一個あたりの値段とかを考える必要があるかと思ったけど、卵の最大個数が100個、最小単位が6個だから、あり得る全てのパターンを考えても十分計算量が足りるからそっちの方が楽だし事故が少なそう、と考え直しました。

提出したもの

b.cpp
int main() {
    int n, s, m, l;
    cin >> n >> s >> m >> l;

    int price = 100100100;

    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            for (int k = 0; k < 20; k++) {
                if (6 * i + 8 * j + 12 * k >= n) {
                    price = min(price, s * i + m * j + l * k);
                } else {
                    continue;
                }
            }
        }
    }
    cout << price << endl;
    return 0;
}

振り返り
1個あたりの値段を考える方針だと、細かな数の処理で失敗する可能性があったから全探索の方針に切り替えられてよかった。

C - Sum of Numbers Greater Than Me

考えてたこと
一番最初に配列全ての総和、それぞれの値の出現回数を保存しておいて、引いていく...みたいな方針で解いてるっぽいんだけどあまりコードが自分のものっぽくない...?
解いたのがしばらく前だから忘れてるけど、アイデアだけ思いついてかなり調べながら解いたとか...?

提出したもの

c.cpp
int main() {
    int n;
    cin >> n;
    vector<int> a(n);

    rep(i, 0, n) cin >> a[i];

    // それぞれのAをキー、実際にAが存在するインデックスの集合の配列を値とするmap
    map<int, vector<int>> map;

    for (int i = 0; i < n; i++) {
        map[a[i]].push_back(i);
    }

    // aという配列に含まれる全ての値の合計値がs
    ll s = accumulate(a.begin(), a.end(), 0LL);

    vector<ll> ans(n);

    // mapに対して範囲for文
    for (auto [v, i_list] : map) {
        // Aより大きな要素、つまりAは含まないので、Aの値*個数をsから引く
        s -= (ll)v * i_list.size();
        // Aのインデックスの集合であるi_listに対して範囲for文
        // i番目の入力値は全てAi, よってi番目の出力値は全てs
        for (auto i : i_list) {
            ans[i] = s;
        }
    }
    for(auto x:ans)cout << x << ' ';
    return 0;
}

振り返り
解答のコードとかとも結構違うし、方針自体は私が思いつきそうなものだし...よくわからない。

感想

振り返りは急いでやりましょう(´・ω・`)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?