結果

問題 No.440 2次元チワワ問題
ユーザー suppy193suppy193
提出日時 2016-11-16 10:28:42
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 4,138 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 24,832 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-05-04 14:16:00
合計ジャッジ時間 9,717 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
13,568 KB
testcase_01 AC 8 ms
13,568 KB
testcase_02 AC 10 ms
13,568 KB
testcase_03 AC 13 ms
13,568 KB
testcase_04 AC 55 ms
13,568 KB
testcase_05 AC 20 ms
13,568 KB
testcase_06 AC 29 ms
13,568 KB
testcase_07 AC 1,604 ms
13,568 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:21:17: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
   21 |                 gets(s);
      |                 ^~~~
      |                 fgets
main.c:19:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         scanf("%d%d\n", &h, &w);
      |         ^~~~~~~~~~~~~~~~~~~~~~~
main.c:35:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d", &q);
      |         ^~~~~~~~~~~~~~~
main.c:56:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |                 scanf("%d%d%d%d", &a, &b, &c, &d);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccLa3krE.o: in function `main':
main.c:(.text.startup+0x106): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #

#include <stdio.h>
#include <string.h>

int main(void) {
	char s[501];
	char field[501][501] = {0};
	int yoko[501][501][3] = {0};
	int yoko_r[501][501][3] = {0};
	int tate[501][501][3] = {0};
	int tate_r[501][501][3] = {0};
	int h, w;
	int q;
	int a, b, c, d;
	int i, k;
	int x, y;
	int xx, yy;
	int cnt;
	int sum_c = 0, sum_cw = 0;
	scanf("%d%d\n", &h, &w);
	for(y = 1;y <= h;y++){
		gets(s);
		for(x = 1;x <= w;x++){
			field[y][x] = s[x - 1];
			//printf("%d:%s\n", i, field[i]);
		}
	}
	/*
	for(y = 1;y <= h;y++){
		for(x = 1;x <= w;x++){
			printf("%c", field[y][x]);
		}
		printf("\n");
	}
	*/
	scanf("%d", &q);
	//printf("q:%d\n", q);
	for(i = 0;i < q;i++){
		cnt = 0;
		/*
		for(y = 0;y <= 500;y++){
			for(x = 0;x <= 500;x++){
				for(k = 0;k < 3;k++){
					//yoko[y][x][k] = 0;
					//tate[y][x][k] = 0;
					//yoko_r[y][x][k] = 0;
					//tate_r[y][x][k] = 0;
				}
			}
		}
		*/
		memset(yoko, (int)0, sizeof(yoko));
		memset(tate, (int)0, sizeof(tate));
		memset(yoko_r, (int)0, sizeof(yoko_r));
		memset(tate_r, (int)0, sizeof(tate_r));
		
		scanf("%d%d%d%d", &a, &b, &c, &d);
		//printf("%d %d %d %d\n", a, b, c, d);

		for(y = a;y <= c;y++){
			sum_c = 0;
			sum_cw = 0;
			for(x = b;x <= d;x++){
				//printf("%c", field[y][x]);
				if(field[y][x] == 'c'){
					yoko[y][x][0] = 1;
					//tate[y][x][0] = 1;
				}
				if(field[y][x] == 'w'){
					/*
					for(xx = b;xx < x;xx++){
						yoko[y][x][1] += yoko[y][xx][0];
						yoko[y][x][2] += yoko[y][xx][1];
					}
					*/
					yoko[y][x][1] = sum_c;
					yoko[y][x][2] = sum_cw;
					/*
					for(yy = a;yy < y;yy++){
						tate[y][x][1] += tate[yy][x][0];
						tate[y][x][2] += tate[yy][x][1];
					}
					*/
				}
				sum_c += yoko[y][x][0];
				sum_cw += yoko[y][x][1];
			}
			//printf("\n");
		}
		//printf("\n");

		for(x = b;x <= d;x++){
			sum_c = 0;
			sum_cw = 0;
			for(y = a;y <= c;y++){
				//printf("%c", field[y][x]);
				if(field[y][x] == 'c'){
					tate[y][x][0] = 1;
				}
				if(field[y][x] == 'w'){
					/*
					for(xx = b;xx < x;xx++){
						yoko[y][x][1] += yoko[y][xx][0];
						yoko[y][x][2] += yoko[y][xx][1];
					}
					*/
					tate[y][x][1] = sum_c;
					tate[y][x][2] = sum_cw;
					/*
					for(yy = a;yy < y;yy++){
						tate[y][x][1] += tate[yy][x][0];
						tate[y][x][2] += tate[yy][x][1];
					}
					*/
				}
				sum_c += tate[y][x][0];
				sum_cw += tate[y][x][1];
			}
			//printf("\n");
		}
		//printf("\n");

		for(y = c;y >= a;y--){
			sum_c = 0;
			sum_cw = 0;
			for(x = d;x >= b;x--){
				//printf("%c", field[y][x]);
				if(field[y][x] == 'c'){
					yoko_r[y][x][0] = 1;
					//tate_r[y][x][0] = 1;
				}
				if(field[y][x] == 'w'){
					/*
					for(xx = d;xx > x;xx--){
						yoko_r[y][x][1] += yoko_r[y][xx][0];
						yoko_r[y][x][2] += yoko_r[y][xx][1];
					}
					*/
					yoko_r[y][x][1] = sum_c;
					yoko_r[y][x][2] = sum_cw;
					/*
					for(yy = c;yy > y;yy--){
						tate_r[y][x][1] += tate_r[yy][x][0];
						tate_r[y][x][2] += tate_r[yy][x][1];
					}
					*/
				}
				sum_c += yoko_r[y][x][0];
				sum_cw += yoko_r[y][x][1];
			}
			//printf("\n");
		}

		for(x = d;x >= b;x--){
			sum_c = 0;
			sum_cw = 0;
			for(y = c;y >= a;y--){
				//printf("%c", field[y][x]);
				if(field[y][x] == 'c'){
					//yoko_r[y][x][0] = 1;
					tate_r[y][x][0] = 1;
				}
				if(field[y][x] == 'w'){
					/*
					for(xx = d;xx > x;xx--){
						yoko_r[y][x][1] += yoko_r[y][xx][0];
						yoko_r[y][x][2] += yoko_r[y][xx][1];
					}
					*/
					//yoko_r[y][x][1] = sum_c;
					//yoko_r[y][x][2] = sum_cw;
					/*
					for(yy = c;yy > y;yy--){
						tate_r[y][x][1] += tate_r[yy][x][0];
						tate_r[y][x][2] += tate_r[yy][x][1];
					}
					*/
					tate_r[y][x][1] = sum_c;
					tate_r[y][x][2] = sum_cw;
				}
				sum_c += tate_r[y][x][0];
				sum_cw += tate_r[y][x][1];
			}
			//printf("\n");
		}

		cnt = 0;
		for(y = a;y <= c;y++){
			for(x = b;x <= d;x++){
				cnt += yoko[y][x][2] + tate[y][x][2] + yoko_r[y][x][2] + tate_r[y][x][2];
			}
		}
		printf("%d\n", cnt);

		/*
		for(y = c;y >= a;y--){
			for(x = d;x >= b;x--){
				printf("%d ", tate_r[y][x][2]);
			}
			printf("\n");
		}
		printf("\n");
		*/		
	}
	
	return 0;
}
0