結果

問題 No.78 クジ付きアイスバー
ユーザー koyumeishikoyumeishi
提出日時 2014-11-26 02:16:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,126 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 23,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 12:45:15
合計ジャッジ時間 10,080 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 237 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 233 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1,078 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 0 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 817 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 993 ms
5,376 KB
testcase_20 AC 908 ms
5,376 KB
testcase_21 AC 1,126 ms
5,376 KB
testcase_22 AC 1,067 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 0 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 0 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 248 ms
5,376 KB
testcase_35 AC 240 ms
5,376 KB
testcase_36 AC 947 ms
5,376 KB
testcase_37 AC 1,015 ms
5,376 KB
testcase_38 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d %d\n%s", &n, &k, s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

//O(K)の愚直解

#include "stdio.h"

int main(){
	int n;
	int k;
	int v[1000];
	char s[100];
	
	int m;
	int block;
	int rem;
	int x;
	int y;
	
	int ans = 0;
	int p = 0;
	int i,j;
	int q = 0;
	
	scanf("%d %d\n%s", &n, &k, s);
	
	m = (250/n) * n;
	block = k/m;
	rem = k%m;
	x = (m/4) * 4;
	y = m%x;
	
	for(i=0; i<m; i++){
		v[i] = (s[(i%n)] - '0');
	}


	for(i=0; i<block; ++i){
		for(j=0; j<x; j+=4){
			if(p == 0) ++ans;
			else --p;
			p += v[j];
			
			if(p == 0) ++ans;
			else --p;
			p += v[j+1];
			
			if(p == 0) ++ans;
			else --p;
			p += v[j+2];
			
			if(p == 0) ++ans;
			else --p;
			p += v[j+3];
		}
		for(j=0; j<y; j++){
			if(p == 0) ++ans;
			else --p;
			p += v[x+j];
		}
		if(p>=n) break;
	}
	for(i=0; i<rem; ++i){
		if(p == 0) ++ans;
		else --p;
		p += v[i];
	}

	printf("%d\n", ans);
	return 0;
}
0