結果

問題 No.626 Randomized 01 Knapsack
ユーザー tailstails
提出日時 2017-12-18 19:29:40
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 750 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 15,816 KB
最終ジャッジ日時 2024-12-16 00:18:33
合計ジャッジ時間 55,231 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,736 KB
testcase_01 AC 1 ms
8,740 KB
testcase_02 AC 1 ms
13,636 KB
testcase_03 AC 1 ms
8,608 KB
testcase_04 AC 266 ms
13,640 KB
testcase_05 AC 1 ms
8,736 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 3 ms
6,824 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'ha':
main.c:12:9: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   12 |         printf("%lld\n",b);
      |         ^~~~~~
main.c:2:1: note: include '<stdio.h>' or provide a declaration of 'printf'
    1 | #include <signal.h>
  +++ |+#include <stdio.h>
    2 | 
main.c:12:9: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   12 |         printf("%lld\n",b);
      |         ^~~~~~
main.c:12:9: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:13:9: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
   13 |         exit(0);
      |         ^~~~
main.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
    1 | #include <signal.h>
  +++ |+#include <stdlib.h>
    2 | 
main.c:13:9: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   13 |         exit(0);
      |         ^~~~
main.c:13:9: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c: At top level:
main.c:44:1: warning: return type defaults to 'int' [-Wimplicit-int]
   44 | main(i){
      | ^~~~
main.c: In function 'main':
main.c:44:1: warning: type of 'i' defaults to 'int' [-Wimplicit-int]
main.c:45:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   45 |         scanf("%d%lld",&n,&c);
      |         ^~~~~
main.c:45:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:45:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
main.c:45:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:49:9: warning: implicit declaration of function 'qsort' [-Wimplicit-function-declaration]
   49 |         qsort(ss,n,sizeof(S),cmp);
      |         ^~~~~
main.c:57:9: warning: implicit declaration of function 'ualarm' [-Wimplicit-function-declaration]
 

ソースコード

diff #

#include <signal.h>

typedef long long ll;
typedef struct{ll v,w,t,u;}S;

int n;
ll c;
ll b;
S ss[6000];

void ha(){
	printf("%lld\n",b);
	exit(0);
}

int sgn(double a){
	return a<0?-1:a>0;
}

int cmp(void*a,void*b){
	S*p=a,*q=b;
	return sgn((double)q->v/q->w-(double)p->v/p->w);
}

void dfs(int i,ll v,ll c){
	if(i==n){
		if(b<v){
			b=v;
		}
	}else{
		if(v+ss[i].t<=b){
			return;
		}
		if(c>=ss[i].w){
			dfs(i+1,v+ss[i].v,c-ss[i].w);
		}
		if(c<ss[i].u){
			dfs(i+1,v,c);
		}
	}
}


main(i){
	scanf("%d%lld",&n,&c);
	for(i=0;i<n;++i){
		scanf("%lld%lld",&ss[i].v,&ss[i].w);
	}
	qsort(ss,n,sizeof(S),cmp);

	ll t=0,u=0;
	for(i=n;i--;){
		ss[i].t=t+=ss[i].v;
		ss[i].u=u+=ss[i].w;
	}
	signal(14,ha);
	ualarm(1900000,0);
	dfs(0,0ll,c);
	raise(14);
}
0