結果

問題 No.241 出席番号(1)
ユーザー h_nosonh_noson
提出日時 2016-05-05 22:46:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 66,876 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 17:54:50
合計ジャッジ時間 1,803 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

int n;
vector<pair<pair<int,int>,int>> e[102];
bool used[102];

int dfs(int v) {
    if (used[v])
        return 0;
    used[v] = true;
    if (v == 2*n+1)
        return 1;
    for (auto& p : e[v]) {
        int to = p.first.first;
        int& cap = p.first.second;
        int rev = p.second;
        if (cap > 0) {
            if (dfs(to)) {
                cap--;
                e[to][rev].first.second++;
                return 1;
            }
        }
    }
    return 0;
}

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

int main() {
    int i, j, flows = 0;
    cin >> n;
    rep (i,n) {
        int a;
        cin >> a;
        rep (j,n) if (j != a) add_edge(i,j+n);
        add_edge(2*n,i);
        add_edge(i+n,2*n+1);
    }
    while (dfs(2*n)) {
        fill(used,used+2*n+2,false);
        flows++;
    }
    if (flows == n) {
        rep (i,n) {
            for (auto p : e[i]) {
                if (p.first.second == 0)
                    cout << p.first.first - n << endl;
            }
        } 
    }
    else
        cout << -1 << endl;
    return 0;
}
0