結果

問題 No.241 出席番号(1)
ユーザー kurenai3110
提出日時 2016-08-23 22:19:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 724 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 72,592 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-11-07 23:28:48
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

int n;
int a[50];
vector<bool> seat;
vector<int> ans;
bool solve(vector<bool> seat,int index) {
	rep(i, n) {
		if (!seat[i] && i!=a[index]) {
			seat[i] = true;
			if (index==n-1) {
				ans[index] = i;
				return true;
			}
			if (solve(seat, index + 1)) {
				ans[index] = i;
				return true;
			}
			else seat[i] = false;
		}
	}
	return false;
}

int main() {

	cin >> n;
	seat.resize(n);
	ans.resize(n);
	rep(i, n) {
		cin >> a[i];
	}
	if (solve(seat, 0)) {
		rep(i, n) {
			cout << ans[i] << endl;
		}
	}
	else cout << -1 << endl;
	return 0;
}
0