結果

問題 No.755 Zero-Sum Rectangle
ユーザー bal4ubal4u
提出日時 2019-07-31 20:20:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 30,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:39:04
合計ジャッジ時間 5,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 91 ms
4,376 KB
testcase_02 AC 72 ms
4,376 KB
testcase_03 AC 95 ms
4,376 KB
testcase_04 AC 110 ms
4,376 KB
testcase_05 AC 123 ms
4,376 KB
testcase_06 AC 78 ms
4,380 KB
testcase_07 AC 71 ms
4,380 KB
testcase_08 AC 102 ms
4,376 KB
testcase_09 AC 112 ms
4,376 KB
testcase_10 AC 127 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: 備考: in expansion of macro ‘gc’
   16 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:29:17: 備考: in expansion of macro ‘pc’
   29 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.755 Zero-Sum Rectangle
// 2019.7.31 bal4u

#include <stdio.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() {  // 整数の入力(負数対応)
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int a[135][135];
ll s[135][135];

int main()
{
	int N, M, r, c, r1, r2, c1, c2, ans;
	
	N = in(), M = in();
	for (r = 1; r <= M; r++) for (c = 1; c <= M; c++) a[r][c] = in();
	for (r = 1; r <= M; r++) for (c = 1; c <= M; c++) {
		s[r][c] = a[r][c] + s[r][c-1] + s[r-1][c] - s[r-1][c-1];
	}

	while (N--) {
		r = in(), c = in(), ans = 0;
		for (r1 = 1; r1 <= r; r1++) for (c1 = 1; c1 <= c; c1++) {
			for (r2 = r; r2 <= M; r2++) for (c2 = c; c2 <= M; c2++) {
				if ((s[r2][c2]-s[r1-1][c2]-s[r2][c1-1]+s[r1-1][c1-1]) == 0) ans++;
			}
		}
		out(ans);
	}
	return 0;
}
0