結果

問題 No.177 制作進行の宮森あおいです!
ユーザー startcpp
提出日時 2015-04-03 00:53:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 3,024 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 84,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 01:30:55
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//
//
//1W2
//1JiXi()
//NP-Hard(
//…(, )
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int w;
int n;
int J[50];
int m;
int C[50];
int ok[50][50]; //ok[J][C]
int Q, X;
int flow[114][114] = {0};
//:1,:0prev使
bool get_incway(int s, int t, int *prev) {
queue<int> que;
bool gone[114] = {false};
que.push(s);
while(!que.empty() ) {
int v = que.front();
que.pop();
if ( gone[v] )
continue;
//cout << v << endl;
gone[v] = true;
if ( v == t )
break;
for(int i = 0; i <= n+m+1; i++ ) {
if ( flow[v][i] >= 1 && !gone[i] ) {
prev[i] = v;
que.push(i);
}
}
}
return gone[t];
}
int Maxflow(int s, int t) {
int prev[114]; //prev[i] = i
int ans = 0;
while( get_incway(s, t, prev) ) {
//
ans++;
//
int no = t;
//cout << endl;
while( no != s ) {
//cout << "no = " << no << endl;
flow[ prev[no] ][no]--; //
flow[no][ prev[no] ]++; //
no = prev[no];
}
}
return ans;
}
//node[0]…node[n+m+1]…() ()
signed main() {
int i, j;
cin >> w;
cin >> n;
for( i = 0; i < n; i++ ) {
cin >> J[i];
flow[0][i+1] = J[i];
}
cin >> m;
for( i = 0; i < m; i++ ) {
cin >> C[i];
}
for( i = 0; i < m; i++ ) {
cin >> Q;
for( j = 0; j < n; j++ ) {
ok[j][i] = 1;
}
for( j = 0; j < Q; j++ ) {
cin >> X;
X--;
ok[X][i] = 0;
}
}
for( i = 0; i < n; i++ ) {
for( j = 0; j < m; j++ ) {
if ( ok[i][j] ) {
//cout << i << " " << j << endl;
flow[i+1][n+1+j] = J[i];
}
}
}
for( i = 0; i < m; i++ ) {
flow[n+1+i][n+m+1] = C[i];
}
/*for( i = 0; i < n+m+2; i++ ) {
for( j = 0; j < n+m+2; j++ ) {
cout << flow[i][j] << " " ;
}
cout << endl;
}*/
//
int maxf = Maxflow(0, n+m+1);
//cout << maxf << endl;
if ( maxf >= w )
cout << "SHIROBAKO" << endl;
else
cout << "BANSAKUTSUKITA" << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0