結果

問題 No.1537 私の代わりに仕事やっといてください。
ユーザー 629e^-b629e^-b
提出日時 2021-06-14 22:14:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,746 bytes
コンパイル時間 4,380 ms
コンパイル使用メモリ 266,656 KB
実行使用メモリ 15,648 KB
最終ジャッジ日時 2023-08-26 08:23:37
合計ジャッジ時間 5,376 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 101 ms
15,648 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<pii> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.rbegin(), A.rend());

    if (N == 2) {
        cout << "1 2 1" << endl;
        return 0;
    }

    Graph<int> G(N);
    for (int i = 0; i < N; ++i) {
        if (i == 0) {
            G[A[i].second].emplace_back(A[i + 1].second);
            G[A[i + 1].second].emplace_back(A[i].second);
            G[A[i].second].emplace_back(A[i + 2].second);
            G[A[i + 2].second].emplace_back(A[i].second);
            continue;
        }
        if (i + 2 < N) {
            G[A[i].second].emplace_back(A[i + 2].second);
            G[A[i + 2].second].emplace_back(A[i].second);
            continue;
        }
        if (i + 1 < N) {
            G[A[i].second].emplace_back(A[i + 1].second);
            G[A[i + 1].second].emplace_back(A[i].second);
        }
    }

    vector<bool> seen(N);
    int now = 0;
    seen[now] = true;
    for (int i = 0; i < N; ++i) {
        cout << now + 1 << " ";
        for (auto ni : G[now]) {
            if (seen[ni])
                continue;
            now = ni;
            seen[now] = true;
            break;
        }
    }

    cout << 1 << endl;

    return 0;
}
0