結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tottoripaper
提出日時 2015-07-19 18:47:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 51,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 10:22:23
合計ジャッジ時間 1,055 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |     scanf("%d", &W);
      |     ~~~~~^~~~~~~~~~
main.cpp:62:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |         scanf("%d", J+i);
      |         ~~~~~^~~~~~~~~~~
main.cpp:66:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |     scanf("%d", &M);
      |     ~~~~~^~~~~~~~~~
main.cpp:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%d", C+i);
      |         ~~~~~^~~~~~~~~~~
main.cpp:81:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   81 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
main.cpp:88:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   88 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~

ソースコード

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

// Ford-Fulkerson
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <tuple>
typedef std::tuple<int,int,int> P;
int W, N, M;
int J[51], C[51];
// [0, N):
// [N, N+M):
// N+M:
// N+M+1:
std::vector<P> G[200];
bool visited[200];
int INF = 1001001001;
void addEdge(int from, int to, int cap){
G[from].emplace_back(to, cap, G[to].size());
G[to].emplace_back(from, 0, G[from].size()-1);
}
int dfs(int v, int f){
if(v == N+M+1){return f;}
visited[v] = true;
for(auto &e : G[v]){
int to, cap, rev;
std::tie(to, cap, rev) = e;
if(visited[to]){continue;}
if(cap == 0){continue;}
int res = dfs(to, std::min(f, cap));
if(res == 0){continue;}
std::get<1>(e) -= res;
std::get<1>(G[to][rev]) += res;
return res;
}
return 0;
}
int maxFlow(){
int f = 0;
while(1){
memset(visited, 0, sizeof(visited));
int x = dfs(N+M, INF);
if(x == 0){return f;}
f += x;
}
}
int main(){
scanf("%d", &W);
scanf("%d", &N);
for(int i=0;i<N;i++){
scanf("%d", J+i);
}
scanf("%d", &M);
for(int i=0;i<M;i++){
scanf("%d", C+i);
}
for(int i=0;i<M;i++){
addEdge(i+N, N+M+1, C[i]);
}
for(int i=0;i<N;i++){
addEdge(N+M, i, J[i]);
}
for(int i=0;i<M;i++){
int q;
scanf("%d", &q);
bool flags[51];
std::fill(flags, flags+51, false);
for(int j=0;j<q;j++){
int x;
scanf("%d", &x);
x -= 1;
flags[x] = true;
}
for(int j=0;j<N;j++){
if(flags[j]){continue;}
addEdge(j, i+N, J[j]);
}
}
// printf("%d\n", maxFlow());
if(maxFlow() >= W){puts("SHIROBAKO");}
else{puts("BANSAKUTSUKITA");}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0