結果

問題 No.241 出席番号(1)
ユーザー KKT89KKT89
提出日時 2020-03-14 02:11:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,597 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 84,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 11:05:21
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long int ll;

struct Edge{
	int to,rev; ll cap;
	Edge(int to,ll cap,int rev):to(to),cap(cap),rev(rev){}
};
// ここの値に注意!!
const int N=150;
const ll INF=1e9;
vector<Edge> g[N];
int level[N]; 
int iter[N];
void add_edge(int s,int t,ll c){
	g[s].push_back(Edge(t,c,g[t].size()));
	g[t].push_back(Edge(s,0,g[s].size()-1));
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> q;
	level[s]=0;
	q.push(s);
	while(q.size()){
		int v=q.front(); q.pop();
		for(auto &e:g[v]){
			if(e.cap>0&&level[e.to]<0){
				level[e.to]=level[v]+1;
				q.push(e.to);
			}
		}
	}
}
ll dfs(int v,int t,ll f){
	if(v==t)return f;
	for(int &i=iter[v];i<g[v].size();i++){
		Edge &e=g[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			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;
}
ll max_flow(int s,int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for(int i=0;i<n;i++){
		int a; cin >> a;
		add_edge(0,i+1,1);
		add_edge(n+i+1,110,1);
		for(int j=0;j<n;j++){
			if(j!=a){
				add_edge(i+1,n+j+1,1);
			}
		}
	}
	int x=max_flow(0,110);
	if(x<n){
		cout << -1 << endl;
	}else{
		for(int i=0;i<n;i++){
			for(auto e:g[i+1]){
				if(e.cap==0){
					cout << e.to-n-1 << endl;
					break;
				}
			}
		}
	}
}

0