1
1

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 ABC408 振り返り #C++

1
Posted at

はじめに

ABC408に参加したので振り返ります。
結果は1冠でした。

A - Timeout

解法

簡単な条件分岐でした。

実装例

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, S;
    cin >> N >> S;
    int T[N];
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }

    if (T[0] > S) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < N - 1; i++) {
        if (T[i + 1] - T[i] > S) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

B - Compression

解法

ソートと重複の排除を行いました。

実装例

#include <bits/stdc++.h>
using namespace std;

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

    bool appeared[101] = {false};

    for (int i = 0; i < N; i++) {
        int val;
        cin >> val;
        if (val >= 1 && val <= 100) {
            appeared[val] = true;
        }
    }

    int M = 0;
    for (int i = 1; i <= 100; i++) {
        if (appeared[i]) {
            M++;
        }
    }

    cout << M << endl;

    bool first_element_printed = false;
    for (int i = 1; i <= 100; i++) {
        if (appeared[i]) {
            if (first_element_printed) {
                cout << " ";
            }
            cout << i;
            first_element_printed = true;
        }
    }
    cout << endl;
}

おわりに

ソートのアルゴリズムがあやふやだったので精進頑張ります。

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?