結果

問題 No.177 制作進行の宮森あおいです!
ユーザー kaakikaaki
提出日時 2024-05-20 23:15:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,345 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 184,044 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-20 23:15:35
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 8 ms
6,944 KB
testcase_10 AC 12 ms
6,944 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
6,940 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;

template< typename flow_t >
struct FordFulkerson {
  struct edge {
    int to;
    flow_t cap;
    int rev;
    bool isrev;
    int idx;
  };

  vector< vector< edge > > graph;
  vector< int > used;
  const flow_t INF;
  int timestamp;

  FordFulkerson(int n) : INF(numeric_limits< flow_t >::max()), timestamp(0) {
    graph.resize(n);
    used.assign(n, -1);
  }

  void add_edge(int from, int to, flow_t cap, int idx = -1) {
    graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false, idx});
    graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true, idx});
  }

  flow_t dfs(int idx, const int t, flow_t flow) {
    if(idx == t) return flow;
    used[idx] = timestamp;
    for(auto &e : graph[idx]) {
      if(e.cap > 0 && used[e.to] != timestamp) {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  flow_t max_flow(int s, int t) {
    flow_t flow = 0;
    for(flow_t f; (f = dfs(s, t, INF)) > 0; timestamp++) {
      flow += f;
    }
    return flow;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      for(auto &e : graph[i]) {
        if(e.isrev) continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);

ll W,N;cin>>W>>N;
vector<ll> J(N);
for(ll i=0;i<N;i++) cin>>J[i];

ll M;cin>>M;
vector<ll> C(M);
for(ll i=0;i<M;i++) cin>>C[i];

vector<vector<bool>> note(M,vector<bool> (N));
for(ll i=0;i<M;i++)  {
  ll Q;cin>>Q;
  for(ll j=0;j<Q;j++) {
    ll x;cin>>x;
    x--;
    note[i][x]=true;
  }
}


FordFulkerson<ll> g(N+M+2);
for(ll i=0;i<N;i++) {
  g.add_edge(0,i+1,J[i]);
}

for(ll i=0;i<M;i++) {
  g.add_edge(N+1+i,N+M+1,C[i]);
}

for(ll i=0;i<M;i++) {
  for(ll j=0;j<N;j++) {
    if(!note[i][j]) g.add_edge(1+j,1+N+i,INF);
  }
}

ll ans=g.max_flow(0,N+M+1);

if(ans>=W) cout<<"SHIROBAKO"<<endl;
else cout<<"BABSAKUTSUKITA"<<endl;




  
}

  
  
0