結果

問題 No.241 出席番号(1)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-08-23 21:57:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,626 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 166,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 13:41:49
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 1 ms
6,940 KB
testcase_17 RE -
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 RE -
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        for (auto& v : vs) {
            os << v << endl;
        }
        return os;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.clear(); A.resize(N); cin >> A;
    }

    void solve() {
        vector<bool> ng_exist(N, false);
        vector<vector<int>> ng_id(N);
        for (int i = 0; i < N; i++) {
            ng_id[A[i]].push_back(i);
            ng_exist[A[i]] = true;
        }
        vector<int> wildcard;
        for (int i = 0; i < N; i++) if (not ng_exist[i]) wildcard.push_back(i);

        //cout << "ng_id: " << ng_id << endl;
        //cout << "wildcard: " << wildcard << endl;

        vector<int> id(N, -1);
        for (int i = 0; i < N; i++) {
            if (ng_id[i].empty()) continue;
            int x = ng_id[i][0];
            int next = (i + 1) % N;
            while (ng_id[next].empty()) next = (next + 1) % N;
            if (i == next) {
                cout << -1 << endl;
                return;
            }
            id[x] = next;
            for (int j = 1; j < ng_id[i].size(); j++) {
                id[ng_id[i][j]] = wildcard.back();
                wildcard.pop_back();
            }
        }
        cout << id << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0