結果

問題 No.241 出席番号(1)
ユーザー Grun1396Grun1396
提出日時 2018-04-05 22:24:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,870 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 73,056 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 17:59:46
合計ジャッジ時間 1,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <string.h>
#include <cstdio>
using namespace std;
typedef long long ll;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
const int INF = 1e9;


struct edge { int to, cap, rev;};
const int MAX_V = 1e4;
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
//    printf("%d,%d,%d\n",from,to,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;
    rep(i,G[v].size()){
        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;
    for(;;){
        memset(used,0,sizeof(used));
        int f = dfs(s,t,INF);
        if(f==0)return flow;
        flow += f;
    }
}

int n;
vector<int> A;
int main(){

    cin >> n;
    
    int s = 2*n+1, t = 2*n + 2;
    A.resize(n);
    rep(i,n){
        cin >> A[i];
    }
    rep(i,n){
        add_edge(s,i,1);//s -> i
        add_edge(i+n,t,1);//i+n -> t
    }
    rep(i,n){
        rep(j,n){
            if(j != A[i]) add_edge(i,j+n,1);
        }
    }
int flow=max_flow(s,t);
//cout << flow<< endl;
    if(flow == n){
        rep(i,n){
            rep(j,G[i].size()){
                if(G[i][j].cap == 0 && G[i][j].to < 2*n+1){
                    
                    cout << G[i][j].to -n << endl;
                    break;
                }
            }
        }
    }else{
        cout << -1 << endl;
    }

    return 0;
}
0