結果

問題 No.324 落ちてた閉路グラフ
コンテスト
ユーザー 👑 tails
提出日時 2015-12-17 10:20:59
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 466 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 223 ms
コンパイル使用メモリ 29,732 KB
最終ジャッジ日時 2026-02-23 20:07:26
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:1: warning: data definition has no type or storage class
    1 | d00[3010],d01[3010],d10[3010],d11[3010];
      | ^~~
main.c:2:1: warning: data definition has no type or storage class
    2 | w[3010];
      | ^
main.c: In function ‘main’:
main.c:5:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
    5 |         scanf("%d%d",&n,&m);
      |         ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | d00[3010],d01[3010],d10[3010],d11[3010];
main.c:14:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   14 |         printf("%d",max(max(d00[m],d01[m]),max(d10[m],d11[m]+w[n-1])));
      |         ^~~~~~
main.c:14:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #
raw source code

d00[3010],d01[3010],d10[3010],d11[3010];
w[3010];
max(a,b){return a>b?a:b;}
main(i,k,n,m){
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i)scanf("%d",w+i);
	for(k=n;k>=0;--k)d00[k]=d01[k]=d10[k]=d11[k]=-999999;
	d00[0]=d11[1]=0;
	for(i=0;i<n-1;++i)for(k=i+3;--k;)
		d00[k]=max(d00[k],d01[k]),
		d10[k]=max(d10[k],d11[k]),
		d01[k]=max(d00[k-1],d01[k-1]+w[i]),
		d11[k]=max(d10[k-1],d11[k-1]+w[i]);
	printf("%d",max(max(d00[m],d01[m]),max(d10[m],d11[m]+w[n-1])));
	return 0;
}
0