結果
| 問題 |
No.179 塗り分け
|
| コンテスト | |
| ユーザー |
suzu
|
| 提出日時 | 2023-05-23 12:36:17 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 3,000 ms |
| コード長 | 1,865 bytes |
| コンパイル時間 | 4,111 ms |
| コンパイル使用メモリ | 107,904 KB |
| 実行使用メモリ | 19,456 KB |
| 最終ジャッジ日時 | 2024-12-23 01:11:22 |
| 合計ジャッジ時間 | 7,671 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
using System.Collections.Generic;
namespace yukicoder
{
enum Colors
{
Black,
White,
Red,
Blue
}
class pg
{
static void Main(string[] args)
{
var line1 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
int H = line1[0];
int W = line1[1];
var defaultColors = new Colors[H,W];
var paintColors = new Colors[H,W];
int bnum = 0;//黒の数
for(int ih = 0;ih < H;ih++)
{
var line2 = Console.ReadLine().Select(c => c.ToString()).ToArray();
for(int iw = 0;iw < W;iw++)
{
if(line2[iw] == "#")
{
defaultColors[ih,iw] = Colors.Black;
bnum++;
}else
{
defaultColors[ih,iw] = Colors.White;
}
}
}
Array.Copy(defaultColors,paintColors,defaultColors.Length);
if(bnum % 2 == 1 || bnum == 0)//黒の数が奇数か0だったらnoを出力
{
Console.WriteLine("NO");
return;
}
for(int gapH = 1 - H;gapH < H;gapH++)//ずれ
{
for(int gapW = 1 - W;gapW < W;gapW++)//ずれ
{
for(int ih = 0;ih < H;ih++)//paint更新
{
for(int iw = 0;iw < W;iw++)//paint更新
{
if(paintColors[ih,iw] == Colors.Black)
{
paintColors[ih,iw] = Colors.Red;
int nextH = ih + gapH;
int nextW = iw + gapW;
if(nextH >= H || nextW >= W || nextH < 0 || nextW < 0 ||paintColors[nextH,nextW] != Colors.Black)//配列を逸脱するか、塗り替え先が黒でないとき失敗
{
goto PaintEnd;
}
paintColors[nextH,nextW] = Colors.Blue;
}
}
}
Console.WriteLine("YES");//最後まで塗り替えられた
return;
PaintEnd:
Array.Copy(defaultColors,paintColors,defaultColors.Length);
}
}
Console.WriteLine("NO");
}
}
}
suzu