結果

問題 No.241 出席番号(1)
ユーザー kurenaifkurenaif
提出日時 2016-08-23 22:30:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,665 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-20 17:55:40
合計ジャッジ時間 2,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

class MaxFlow {
	struct Edge {
		int to, cap, rev; 
		Edge(int t, int c, int r) :to(t), cap(c), rev(r){}
	};

public:

	vector<vector<Edge> > G;
	vector<bool > used;

	MaxFlow(int MAX_V) :G(MAX_V), used(MAX_V) {}

	void add_edge(int from, int to, int cap) {
		G[from].push_back(Edge(to,cap,G[to].size()));
		G[to].push_back(Edge(from, 0, 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] and 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 (true) {
			fill(ALL(used), false);
			int f = dfs(s, t, 0x3f3f3f3f);
			if(f == 0) return flow;
			flow += f;
		}
	}
};

int main() {
	int N; cin >> N;
	vector<int> A(N); for (auto &a : A) cin >> a;
	
	MaxFlow flow(2 * N + 3);

	REP(i, N) {
		flow.add_edge(0, i + 1, 1);
		for (int j = 0; j < N; ++j) if(A[i] != j) flow.add_edge(i + 1, N + j + 1, 1);
		flow.add_edge(N + i + 1, 2 * N+2 , 1);
	}

	int cnt = flow.max_flow(0, 2 * N + 2);
	if (cnt < N) {
		cout << -1 << endl;
		return 0;
	}

	REP(i, N) {
		int res = -1;
		for (auto e: flow.G[i + 1]) {
			if (e.to >= N + 1 and e.to < 2 * N + 1 and e.cap == 0) {
				cout << e.to - N - 1 << endl;
				break;
			}
		}
	}
	return 0;
}
0