結果

問題 No.241 出席番号(1)
ユーザー nksk38nksk38
提出日時 2017-10-15 16:00:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,916 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 80,524 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 17:59:07
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

const int INF = 1e9;
const int MAX_V = 3000;

int N, M;
struct Flow {
	struct edge {
		int to, cap, rev;
	};
	vector<edge> G[MAX_V];
	bool used[MAX_V];

	void add_edge(int from, int to, int cap) {
		G[from].push_back( { to, cap, (int)G[to].size() });
		G[to].push_back( { from, 0, (int)G[from].size() - 1 });
	}

	
	int dfs(int v, int t, int f) {
		if (v == t) return f;
		used[v] = true;
		for (int i = 0; i < G[v].size(); ++i) {
			edge &e = G[v][i];
			if (!used[e.to] && e.cap > 0) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int max_flow(int s, int t) {
		int flow = 0;
		while (1) {
			memset(used, 0, sizeof(used));
			int f = dfs(s, t, INF);
			if (f == 0) return flow;
			flow += f;
		}
	}
};

int n;

int main(void) {
	cin >> n;
	vector<int> a(n);
	int s = n + n, t = n + n + 1;
	Flow mf;

	rep(i, n)cin >> a[i];
	rep(i, n) mf.add_edge(0,i+1,1);
	rep(i, n) mf.add_edge(n+i+1,200,1);
	rep(i, n)rep(j, n) {
		if (a[i] != j) {
			mf.add_edge(i+1,n+j+1,1);
		}
	}
	if (mf.max_flow(0, 200) != n)
		cout << -1 << endl;
	else {
		rep(i, n) {
			int x = -1;
			rep(j, mf.G[i+1].size()) {
				if (mf.G[i+1][j].to >= n + 1 && mf.G[i+1][j].cap == 0)
					x =mf.G[i+1][j].to - n - 1;
			}
			cout << x << endl;
		}
	}
	return 0;
}
0