Submission #49494907
Source Code Expand
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
namespace Tasks;
public class D
{
public static void Main()
{
using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve()
{
var (H, W, K) = Scanner.Scan<int, int, int>();
var S = new char[H][];
for (var i = 0; i < H; i++)
{
S[i] = Scanner.Scan<string>().ToCharArray();
}
var oX = new long[H, W + 1];
var oY = new long[H + 1, W];
var xX = new long[H, W + 1];
var xY = new long[H + 1, W];
const long Inf = 1 << 30;
for (var i = 0; i < H; i++)
{
for (var j = 0; j < W; j++)
{
if (S[i][j] == 'o')
{
oX[i, j + 1] = 1;
oY[i + 1, j] = 1;
}
else if (S[i][j] == 'x')
{
xX[i, j + 1] = 1;
xY[i + 1, j] = 1;
}
}
}
for (var i = 0; i < H; i++)
{
for (var j = 0; j < W; j++)
{
oX[i, j + 1] += oX[i, j];
xX[i, j + 1] += xX[i, j];
}
}
for (var j = 0; j < W; j++)
{
for (var i = 0; i < H; i++)
{
oY[i + 1, j] += oY[i, j];
xY[i + 1, j] += xY[i, j];
}
}
var answer = Inf;
for (var i = 0; i < H; i++)
{
for (var j = 0; j + K <= W; j++)
{
var o = oX[i, j + K] - oX[i, j];
var x = xX[i, j + K] - xX[i, j];
if (x == 0) answer = Math.Min(answer, K - o);
}
}
for (var j = 0; j < W; j++)
{
for (var i = 0; i + K <= H; i++)
{
if (S[i][j] == 'x') continue;
var o = oY[i + K, j] - oY[i, j];
var x = xY[i + K, j] - xY[i, j];
if (x == 0) answer = Math.Min(answer, K - o);
}
}
if (answer == Inf) answer = -1;
Console.WriteLine(answer);
// Console.WriteLine();
// Printer.Print2D(oX, " ");
// Console.WriteLine();
// Printer.Print2D(oY, " ");
// Console.WriteLine();
// Printer.Print2D(xX, " ");
// Console.WriteLine();
// Printer.Print2D(xY, " ");
}
public static class Printer
{
public static void Print<T>(T source) => Console.WriteLine(source);
public static void Print1D<T>(IEnumerable<T> source, string separator = "") => Console.WriteLine(string.Join(separator, source));
public static void Print1D<T, U>(IEnumerable<T> source, Func<T, U> selector, string separator = "") => Console.WriteLine(string.Join(separator, source.Select(selector)));
public static void Print2D<T>(IEnumerable<IEnumerable<T>> source, string separator = "") => Console.WriteLine(string.Join(Environment.NewLine, source.Select(x => string.Join(separator, x))));
public static void Print2D<T, U>(IEnumerable<IEnumerable<T>> source, Func<T, U> selector, string separator = "") => Console.WriteLine(string.Join(Environment.NewLine, source.Select(x => string.Join(separator, x.Select(selector)))));
public static void Print2D<T>(T[,] source, string separator = "")
{
var (h, w) = (source.GetLength(0), source.GetLength(1));
for (var i = 0; i < h; i++)
{
for (var j = 0; j < w; j++)
{
Console.Write(source[i, j]);
Console.Write(j == w - 1 ? Environment.NewLine : separator);
}
}
}
public static void Print2D<T, U>(T[,] source, Func<T, U> selector, string separator = "")
{
var (h, w) = (source.GetLength(0), source.GetLength(1));
for (var i = 0; i < h; i++)
{
for (var j = 0; j < w; j++)
{
Console.Write(selector(source[i, j]));
Console.Write(j == w - 1 ? Environment.NewLine : separator);
}
}
}
}
public static class Scanner
{
public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
{
var input = ScanStringArray();
return (Convert<T1>(input[0]), Convert<T2>(input[1]));
}
public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
{
var input = ScanStringArray();
return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
}
public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
{
var input = ScanStringArray();
return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
}
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
{
var input = ScanStringArray();
return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
}
public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
{
var input = ScanStringArray();
return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
}
public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
private static string[] ScanStringArray()
{
var line = Console.ReadLine()?.Trim() ?? string.Empty;
return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
}
private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
}
}
Submission Info
| Submission Time |
|
| Task |
D - Cheating Gomoku Narabe |
| User |
AconCavy |
| Language |
C# 11.0 (.NET 7.0.7) |
| Score |
400 |
| Code Size |
6906 Byte |
| Status |
AC |
| Exec Time |
114 ms |
| Memory |
59968 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt, example2.txt, example3.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
44 ms |
24808 KiB |
| 001.txt |
AC |
44 ms |
24828 KiB |
| 002.txt |
AC |
41 ms |
24768 KiB |
| 003.txt |
AC |
47 ms |
32360 KiB |
| 004.txt |
AC |
47 ms |
32532 KiB |
| 005.txt |
AC |
47 ms |
32472 KiB |
| 006.txt |
AC |
54 ms |
32704 KiB |
| 007.txt |
AC |
109 ms |
59960 KiB |
| 008.txt |
AC |
107 ms |
59968 KiB |
| 009.txt |
AC |
102 ms |
59696 KiB |
| 010.txt |
AC |
114 ms |
59784 KiB |
| 011.txt |
AC |
54 ms |
32984 KiB |
| 012.txt |
AC |
50 ms |
33256 KiB |
| 013.txt |
AC |
51 ms |
32844 KiB |
| 014.txt |
AC |
53 ms |
34296 KiB |
| 015.txt |
AC |
52 ms |
32924 KiB |
| 016.txt |
AC |
48 ms |
32736 KiB |
| 017.txt |
AC |
44 ms |
32972 KiB |
| 018.txt |
AC |
60 ms |
32892 KiB |
| 019.txt |
AC |
50 ms |
32996 KiB |
| 020.txt |
AC |
48 ms |
33040 KiB |
| 021.txt |
AC |
49 ms |
32624 KiB |
| 022.txt |
AC |
52 ms |
33000 KiB |
| 023.txt |
AC |
48 ms |
32968 KiB |
| 024.txt |
AC |
52 ms |
32680 KiB |
| 025.txt |
AC |
54 ms |
32780 KiB |
| 026.txt |
AC |
50 ms |
33104 KiB |
| 027.txt |
AC |
51 ms |
33156 KiB |
| 028.txt |
AC |
49 ms |
32652 KiB |
| 029.txt |
AC |
52 ms |
32864 KiB |
| 030.txt |
AC |
48 ms |
33536 KiB |
| 031.txt |
AC |
45 ms |
32856 KiB |
| 032.txt |
AC |
52 ms |
32852 KiB |
| 033.txt |
AC |
59 ms |
32648 KiB |
| 034.txt |
AC |
50 ms |
33684 KiB |
| 035.txt |
AC |
58 ms |
33044 KiB |
| 036.txt |
AC |
47 ms |
32688 KiB |
| 037.txt |
AC |
61 ms |
34832 KiB |
| 038.txt |
AC |
49 ms |
32672 KiB |
| 039.txt |
AC |
52 ms |
32672 KiB |
| 040.txt |
AC |
50 ms |
33856 KiB |
| 041.txt |
AC |
51 ms |
32800 KiB |
| 042.txt |
AC |
46 ms |
32600 KiB |
| 043.txt |
AC |
55 ms |
32976 KiB |
| 044.txt |
AC |
56 ms |
32856 KiB |
| 045.txt |
AC |
45 ms |
32672 KiB |
| 046.txt |
AC |
49 ms |
32960 KiB |
| 047.txt |
AC |
44 ms |
32820 KiB |
| 048.txt |
AC |
49 ms |
33016 KiB |
| 049.txt |
AC |
40 ms |
32696 KiB |
| 050.txt |
AC |
51 ms |
32912 KiB |
| 051.txt |
AC |
48 ms |
32748 KiB |
| 052.txt |
AC |
47 ms |
32700 KiB |
| 053.txt |
AC |
49 ms |
32600 KiB |
| 054.txt |
AC |
52 ms |
32828 KiB |
| 055.txt |
AC |
60 ms |
33192 KiB |
| 056.txt |
AC |
48 ms |
32884 KiB |
| 057.txt |
AC |
56 ms |
33240 KiB |
| 058.txt |
AC |
45 ms |
32836 KiB |
| 059.txt |
AC |
49 ms |
32996 KiB |
| 060.txt |
AC |
50 ms |
32868 KiB |
| 061.txt |
AC |
46 ms |
32972 KiB |
| 062.txt |
AC |
54 ms |
32968 KiB |
| example0.txt |
AC |
42 ms |
24596 KiB |
| example1.txt |
AC |
44 ms |
24944 KiB |
| example2.txt |
AC |
48 ms |
24752 KiB |
| example3.txt |
AC |
47 ms |
24832 KiB |