結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 248 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 239 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 1,074 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 0 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 822 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1,009 ms
5,376 KB
testcase_20 AC 926 ms
5,376 KB
testcase_21 AC 1,131 ms
5,376 KB
testcase_22 AC 1,062 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 0 ms
5,376 KB
testcase_25 AC 0 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 0 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 244 ms
5,376 KB
testcase_35 AC 256 ms
5,376 KB
testcase_36 AC 969 ms
5,376 KB
testcase_37 AC 1,130 ms
5,376 KB
testcase_38 AC 1 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 = (200/n) * n;
	block = k/m;
	rem = k%m;
	x = (m/4) * 4;
	y = m%x;
	
	for(i = j = 0; i<m; ++i, ++j){
		if(j==n) j=0;
		v[i] = (s[j] - '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