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 343 振り返り

Posted at

ABC343

概要

A - Wrong Answer

考えてたこと
簡単でどうやって実装するか逆に悩んだ問題。
確実に存在しているからとりあえず0から9全部回す方針で。

提出したもの

a.cpp
int main() {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 10; i++) {
        if (a + b != i) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

振り返り
特になし。

B - Adjacency Matrix

考えてたこと
グラフの情報を全部二次元配列に保存して、for文で中身全部確認すれば良いかなぁと思ったらそれでAC。

提出したもの

b.cpp
int main() {
    int n;
    cin >> n;

    int graph[n][n];
    rep(i, 0, n) {
        rep(j, 0, n) {
            cin >> graph[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (graph[i][j] == 1) {
                cout << j + 1 << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

振り返り
特になし。

C - 343

考えてたこと
Nの三乗根?を全部探索すれば解は求められてNが10^18上限だから計算量足りそうと思ってシンプルに実装、AC。

提出したもの

c.cpp
int main() {
    ll n;
    cin >> n;
    ll ans;
    for (ll i = 0; i * i * i <= n; i++) {
        ll now = i * i * i;
        string now_string = to_string(now);
        string copy = now_string;
        reverse(now_string.begin(), now_string.end());
        if (copy == now_string) {
            ans = now;
        }
    }
    cout << ans << endl;
    return 0;
}

振り返り
特になし、って言えるぐらいC問題の中では簡単に解けた。

D - Diversity of Scores

考えてたこと
データをどのように保持するか悩んだ問題。現在のそれぞれの選手の得点、選手の得点の種類を常に保持し続けたくてmapを二つ作成すれば良いかなという方針で実装。無事AC。

提出したもの

d.cpp
int main() {
    int n, t;
    cin >> n >> t;

    map<int, ll> people;
    map<ll, int> count;

    // 全員の点数を初期化
    for (int i = 0; i < n; i++) {
        people[i] = 0;
    }

    count[0] = n;

    for (int i = 0; i < t; i++) {
        int a, b;
        cin >> a >> b;
        a--;

        count[people[a]]--;
        if (count[people[a]] <= 0) {
            count.erase(people[a]);
        }
        people[a] += b;
        if (count.count(people[a])) {
            count[people[a]]++;
        } else {
            count[people[a]] = 1;
        }

        cout << count.size() << endl;
    }
    return 0;
}

振り返り
解説を見てみたら現在の選手の得点に関してはmapを使わなくてvectorで良かった。確かに1からNで全部揃ってるからこういう時はvectorで十分そう。keyの値がランダム、というか綺麗に並んでいない時だけmapを使うように心がけたい。

感想

ここまでスムーズにD問題まで解けたのは初めてかも。
問題が簡単だったのはあるけど、とはいえ嬉しい。

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?