結果
問題 | No.241 出席番号(1) |
ユーザー |
|
提出日時 | 2016-08-23 21:45:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,052 bytes |
コンパイル時間 | 966 ms |
コンパイル使用メモリ | 100,896 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:36:07 |
合計ジャッジ時間 | 2,294 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <set>#include <random>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)using namespace std;int main() {int n; cin >> n;vector<int> a(n); repeat (i,n) cin >> a[i];if (whole(count, a, a[0]) == n and 0 <= a[0] and a[0] < n) {cout << -1 << endl; // all a_i is the same} else {vector<int> b(n); whole(iota, b, 0);set<int> c; repeat (i,n) if (a[i] == b[i]) c.insert(i);default_random_engine gen((random_device())());uniform_int_distribution<int> dist(0, n-1);while (not c.empty()) {int i = *c.begin();int j = i; while (j == i) j = dist(gen);swap(b[i], b[j]);c.erase(i);c.erase(j);if (a[i] == b[i]) c.insert(i);if (a[j] == b[j]) c.insert(j);}for (int it : b) cout << it << endl;}return 0;}