結果

問題 No.78 クジ付きアイスバー
ユーザー 👑 testestesttestestest
提出日時 2016-10-30 03:45:20
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 487 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 20,096 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 19:44:10
合計ジャッジ時間 1,445 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 0 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 0 ms
6,940 KB
testcase_09 AC 0 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 0 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 0 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 0 ms
6,940 KB
testcase_19 AC 0 ms
6,940 KB
testcase_20 AC 0 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 0 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 0 ms
6,940 KB
testcase_26 AC 0 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 0 ms
6,940 KB
testcase_30 AC 0 ms
6,944 KB
testcase_31 AC 0 ms
6,944 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 0 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 AC 0 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:1: warning: data definition has no type or storage class
    2 | n,k,x,y;
      | ^
main.c:2:1: warning: type defaults to ‘int’ in declaration of ‘n’ [-Wimplicit-int]
main.c:2:3: warning: type defaults to ‘int’ in declaration of ‘k’ [-Wimplicit-int]
    2 | n,k,x,y;
      |   ^
main.c:2:5: warning: type defaults to ‘int’ in declaration of ‘x’ [-Wimplicit-int]
    2 | n,k,x,y;
      |     ^
main.c:2:7: warning: type defaults to ‘int’ in declaration of ‘y’ [-Wimplicit-int]
    2 | n,k,x,y;
      |       ^
main.c: In function ‘main’:
main.c:21:9: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
   21 |         scanf("%d%d%s",&n,&k,box);
      |         ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | char box[60];
main.c:21:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   21 |         scanf("%d%d%s",&n,&k,box);
      |         ^~~~~
main.c:21:9: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
main.c:22:16: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
   22 |         if(k<n)printf("%d",hasuu(k,0));
      |                ^~~~~~
main.c:22:16: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:22:16: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
main.c:22:16: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:25:25: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   25 |                 if(x<=y)printf("%d",x);
      |                         ^~~~~~
main.c:25:25: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:26:22: warning: incompatible implicit declaration of built-in function ��

ソースコード

diff #

char box[60];
n,k,x,y;
void hakogai(){
	int stock=0,cost=0,i;
	for(i=0;i<n;i++){
		if(stock>0)stock--;else cost++;
		stock+=box[i]-'0';
	}
	x=cost;
	y=stock;
}
int hasuu(int rest,int stock){
	int cost=0,i;
	for(i=0;i<rest;i++){
		if(stock>0)stock--;else cost++;
		stock+=box[i]-'0';
	}
	return cost;
}
int main(){
	scanf("%d%d%s",&n,&k,box);
	if(k<n)printf("%d",hasuu(k,0));
	else {
		hakogai();
		if(x<=y)printf("%d",x);
		else printf("%d",x+(x-y)*(k/n-1)+hasuu(k%n,y));
	}
	return 0;
}
0