結果
| 問題 |
No.241 出席番号(1)
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-08-23 21:57:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,626 bytes |
| コンパイル時間 | 1,565 ms |
| コンパイル使用メモリ | 165,720 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 00:40:40 |
| 合計ジャッジ時間 | 5,879 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 5 RE * 9 |
ソースコード
#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;
}
izuru_matsuura