結果

問題 No.3558 Dominoes, Black and White
コンテスト
ユーザー pengin_2000
提出日時 2026-05-29 22:07:48
言語 C
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 671 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 802 ms
コンパイル使用メモリ 40,928 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-29 22:07:54
合計ジャッジ時間 6,012 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 10 % AC * 30
満点 90 % AC * 89
合計 100 点
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: warning: conflicting types for built-in function 'abs'; expected 'int(int)' [-Wbuiltin-declaration-mismatch]
    2 | long long int abs(long long int n)
      |               ^~~
main.c:2:1: note: 'abs' is declared in header '<stdlib.h>'
    1 | #include<stdio.h>
  +++ |+#include <stdlib.h>
    2 | long long int abs(long long int n)

ソースコード

diff #
raw source code

#include<stdio.h>
long long int abs(long long int n)
{
	if (n < 0)
		return -n;
	else
		return n;
}
char s[1003][2003];
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i, j;
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	long long int ans = 0, cnt = 0;
	for (j = 0; j< n; j++)
	{
		for (i = 0; i < n; i++)
			if (s[i][j] == '#')
				cnt++;
		ans += cnt;
	}
	for (; j < 2 * n; j++)
	{
		for (i = 0; i < n; i++)
			if (s[i][j] == '#')
				cnt++;
		ans += cnt - n * (j - n + 1);
	}
	cnt = 0;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 2 * n; j++)
			if (s[i][j] == '#')
				cnt++;
		ans += abs(cnt - n * (i + 1));
	}
	printf("%lld\n", ans);
	return 0;
}
0