結果
問題 | No.241 出席番号(1) |
ユーザー |
![]() |
提出日時 | 2016-03-29 14:29:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,457 bytes |
コンパイル時間 | 720 ms |
コンパイル使用メモリ | 87,348 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:35:08 |
合計ジャッジ時間 | 1,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
/* -*- coding: utf-8 -*-** 241.cc: No.241 出席番号(1) - yukicoder*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<deque>#include<algorithm>#include<numeric>#include<utility>#include<complex>#include<functional>using namespace std;/* constant */const int MAX_N = 50;typedef long long ll;const ll NBITS = 1LL << MAX_N;/* typedef */typedef pair<int,int> pii;/* global variables */int n;int as[MAX_N], sis[MAX_N];ll ics[MAX_N];pii sts[MAX_N];/* subroutines */inline int bnums(int n, ll bits) {int bn = 0;for (int i = 0; i < n; i++)if (bits & (1LL << i)) bn++;return bn;}void finish() {for (int i = 0; i < n; i++) printf("%d\n", sis[i]);exit(0);}void rec(int u) {if (u >= n) finish();int &ui = sts[u].second;for (int i = 0; i < n; i++) {if (sis[i] < 0 && (ics[ui] & (1LL << i)) != 0) {sis[i] = ui;rec(u + 1);sis[i] = -1;}}}/* main */int main() {cin >> n;ll nbits = 1LL << n;for (int i = 0; i < n; i++) sis[i] = -1, ics[i] = nbits - 1;for (int i = 0; i < n; i++) {cin >> as[i];ics[as[i]] &= ~(1LL << i);}for (int i = 0; i < n; i++) {int bn = bnums(n, ics[i]);sts[i] = pii(bn, i);}sort(sts, sts + n);rec(0);puts("-1");return 0;}