Submission #33998636


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 C
    {
        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (H1, W1) = Scanner.Scan<int, int>();
            var A = new int[H1][];
            for (var i = 0; i < H1; i++)
            {
                A[i] = Scanner.ScanEnumerable<int>().ToArray();
            }

            var (H2, W2) = Scanner.Scan<int, int>();
            var B = new int[H2][];
            for (var i = 0; i < H2; i++)
            {
                B[i] = Scanner.ScanEnumerable<int>().ToArray();
            }

            for (var H = 0; H < 1 << H1; H++)
            {
                var hc = 0;
                for (var k = 0; k < H1; k++)
                {
                    if ((H >> k & 1) == 1) hc++;
                }
                if (hc != H2) continue;

                for (var W = 0; W < 1 << W1; W++)
                {
                    var wc = 0;
                    for (var k = 0; k < W1; k++)
                    {
                        if ((W >> k & 1) == 1) wc++;
                    }

                    if (wc != W2) continue;

                    var G = new List<List<int>>();
                    for (var i = 0; i < H1; i++)
                    {
                        if ((H >> i & 1) == 1) G.Add(new List<int>());
                        else continue;

                        for (var j = 0; j < W1; j++)
                        {
                            if ((W >> j & 1) == 1) G[^1].Add(A[i][j]);
                        }
                    }

                    var ok = true;
                    for (var i = 0; i < H2; i++)
                    {
                        for (var j = 0; j < W2; j++)
                        {
                            ok &= G[i][j] == B[i][j];
                        }
                    }

                    if (ok)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            Console.WriteLine("No");
        }

        public static class Scanner
        {
            public static string ScanLine() => Console.ReadLine()?.Trim() ?? string.Empty;
            public static string[] Scan() => ScanLine().Split(' ');
            public static T Scan<T>() where T : IConvertible => Convert<T>(Scan()[0]);
            public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]));
            }
            public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[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 line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[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 line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[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 line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]), Convert<T6>(line[5]));
            }
            public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => Scan().Select(Convert<T>);
            private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
        }
    }
}

Submission Info

Submission Time
Task C - Matrix Reducing
User AconCavy
Language C# (.NET Core 3.1.201)
Score 300
Code Size 4767 Byte
Status AC
Exec Time 178 ms
Memory 46944 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 32
Set Name Test Cases
Sample example0.txt, example1.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, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 76 ms 27864 KiB
001.txt AC 82 ms 27764 KiB
002.txt AC 78 ms 28352 KiB
003.txt AC 75 ms 28360 KiB
004.txt AC 69 ms 28332 KiB
005.txt AC 90 ms 27976 KiB
006.txt AC 86 ms 27884 KiB
007.txt AC 82 ms 28024 KiB
008.txt AC 78 ms 28176 KiB
009.txt AC 80 ms 27872 KiB
010.txt AC 175 ms 46936 KiB
011.txt AC 176 ms 46768 KiB
012.txt AC 168 ms 46744 KiB
013.txt AC 167 ms 46752 KiB
014.txt AC 78 ms 28156 KiB
015.txt AC 81 ms 27932 KiB
016.txt AC 85 ms 28152 KiB
017.txt AC 82 ms 28028 KiB
018.txt AC 75 ms 28360 KiB
019.txt AC 98 ms 32852 KiB
020.txt AC 159 ms 46752 KiB
021.txt AC 170 ms 46748 KiB
022.txt AC 140 ms 46552 KiB
023.txt AC 178 ms 46612 KiB
024.txt AC 170 ms 46944 KiB
025.txt AC 175 ms 46932 KiB
026.txt AC 77 ms 28040 KiB
027.txt AC 83 ms 28368 KiB
028.txt AC 82 ms 27928 KiB
029.txt AC 76 ms 28468 KiB
example0.txt AC 79 ms 27980 KiB
example1.txt AC 86 ms 27984 KiB