結果

問題 No.177 制作進行の宮森あおいです!
ユーザー akakimidoriakakimidori
提出日時 2018-07-11 01:51:42
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,770 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 28,040 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 08:11:34
合計ジャッジ時間 1,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*(n+m+2)+(j))

int flow(int *g,int n,int m){
  int used[102];
  int dp[102];
  int i;
  for(i=0;i<n+m+2;i++){
    used[i]=0;
    dp[i]=0;
  }
  dp[0]=10000;
  int memo[102];
  int len=0;
  while(1){
    int max=0;
    int maxIndex=-1;
    for(i=0;i<n+m+2;i++){
      if(!used[i] && dp[i]>max){
	max=dp[i];
	maxIndex=i;
      }
    }
    if(max==0) break;
    used[maxIndex]=1;
    memo[len++]=maxIndex;
    for(i=0;i<n+m+2;i++){
      dp[i]=MAX(dp[i],MIN(dp[maxIndex],g[POS(maxIndex,i)]));
    }
  }
  if(dp[n+m+1]==0) return 0;
  int now=n+m+1;
  int f=dp[now];
  for(i=len-1;now!=0;i--){
    int k=memo[i];
    if(dp[k]>=f && g[POS(k,now)]>=f){
      g[POS(k,now)]-=f;
      g[POS(now,k)]+=f;
      now=k;
    }
  }
  return f;
}

void run(void){
  int w;
  scanf("%d",&w);
  int n;
  scanf("%d",&n);
  int genga[50];
  int i;
  for(i=0;i<n;i++) scanf("%d",genga+i);
  int m;
  scanf("%d",&m);
  int sakuga[50];
  for(i=0;i<m;i++) scanf("%d",sakuga+i);
  int graph[10404];
  int j;
  for(i=0;i<n+m+2;i++){
    for(j=0;j<n+m+2;j++){
      graph[POS(i,j)]=0;
    }
  }
  for(i=0;i<n;i++) graph[POS(0,i+1)]=genga[i];
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      graph[POS(i+1,n+1+j)]=10000;
    }
  }
  for(i=0;i<m;i++) graph[POS(n+1+i,n+m+1)]=sakuga[i];
  for(i=0;i<m;i++){
    int q;
    scanf("%d",&q);
    while(q--){
      int x;
      scanf("%d",&x);
      graph[POS(x,n+1+i)]=0;
    }
  }
  int f=0;
  while(w>0 && (f=flow(graph,n,m),f>0)) w-=f;
  printf("%s\n",w<=0?"SHIROBAKO":"BANSAKUTSUKITA");
  return;
}

int main(void){
  run();
  return 0;
}
0