結果

問題 No.78 クジ付きアイスバー
ユーザー koyumeishikoyumeishi
提出日時 2014-11-26 02:15:42
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 1,194 ms / 5,000 ms
コード長 901 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 00:05:11
合計ジャッジ時間 11,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

//愚直解で通るのかしら

#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=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