{"id":3023,"date":"2025-02-06T02:47:47","date_gmt":"2025-02-06T02:47:47","guid":{"rendered":"https:\/\/histy.jp\/?p=3023"},"modified":"2025-02-06T02:47:48","modified_gmt":"2025-02-06T02:47:48","slug":"post-3023","status":"publish","type":"post","link":"https:\/\/histy.jp\/?p=3023","title":{"rendered":"\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u9244\u5247\u3092C#\u3067\u89e3\u3044\u3066\u307f\u305f\u3002A14 &#8211; Four Boxes"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u554f\u984c<\/h2>\n\n\n\n<p><a href=\"https:\/\/atcoder.jp\/contests\/tessoku-book\/tasks\/tessoku_book_n\">A14 &#8211; Four Boxes<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8003\u3048\u65b9<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u554f\u984c\u6587\u3092\u7406\u89e3\u3059\u308b\u3002<\/h4>\n\n\n\n<p>A\u3001B\u3001C\u3001D4\u3064\u306e\u6570\u5217\u304c\u4e0e\u3048\u3089\u308c\u308b\u306e\u3067\u3001\u5404\u6570\u5217\u304b\u30891\u3064\u305a\u3064\u5024\u3092\u9078\u3093\u3067\u5408\u7b97\u3057\u305f\u5024\u304ck\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308b\u304b\u3092\u554f\u308f\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u8aac<\/h4>\n\n\n\n<p>\u307e\u305a\u306f\u5168\u63a2\u7d22\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nusing System.Collections.Generic;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        bool result = Solve();\n        if (result) Console.WriteLine(\"Yes\");\n        else Console.WriteLine(\"No\");\n    }\n\n    private static bool Solve()\n    {\n        int&#91;] nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int n = nk&#91;0];\n        int k = nk&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] b = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] c = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n\n        for (int f = 0; f &lt; n; f++)\n        {\n            for (int s = 0; s &lt; n; s++)\n            {\n                for(int t = 0; t &lt; n; t++)\n                {\n                    for(int fourth = 0; fourth &lt; n; fourth++)\n                    {\n                        long sum = 0;\n                        sum += a&#91;f];\n                        sum += b&#91;s];\n                        sum += c&#91;t];\n                        sum += d&#91;fourth];\n                        if (sum == k) return true;\n                    }\n                }\n            }\n        }\n\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u305f\u3060\u3057\u3001\u5404\u6570\u5217\u306e\u8981\u7d20\u6570\u306f\u6700\u5927\u306710\u306e3\u4e57\u3002<br>\u3053\u308c\u3060\u3068\u3001\u8a08\u7b97\u91cf\u304c4\u91cd\u306efor\u30eb\u30fc\u30d7\u306710\u306e12\u4e57\u3092\u8d85\u3048\u3066\u3057\u307e\u3046\u3002<br>TLE\u3002\u3053\u3053\u3092\u89e3\u6c7a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u25a0\u30d1\u30bf\u30fc\u30f3\uff11<\/h5>\n\n\n\n<p>\u6570\u5217A\u3001B\u3001C\u3001D\u3092A\u3068B\u3001C\u3068D\u306b\u5206\u3051\u3066\u3001\u305d\u308c\u305e\u308c\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u304a\u3044\u3066\u5168\u3066\u306e\u7d44\u307f\u5408\u308f\u305b\u306b\u5bfe\u3057\u3066\u5408\u8a08\u3092\u7b97\u51fa\u3059\u308b\u3002<br>\u7247\u65b9\u306e\u30b0\u30eb\u30fc\u30d7\u304b\u3089\u6c42\u307e\u308b\u5024\u3092k\u304b\u3089\u5f15\u3044\u305f\u5024\u3092\u6c42\u3081\u308b\u3002<br>\u3082\u3046\u4e00\u65b9\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u305d\u306e\u5024\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3092\u6c42\u3081\u308b\u3002<\/p>\n\n\n\n<p>\u6570\u5217A\u3001B\u3001C\u3001D\u3092 (A\u3068B)\u3001(C\u3068D) \u306e2\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u5206\u3051\u308b\u3002<br>\u305d\u308c\u305e\u308c\u306e\u30b0\u30eb\u30fc\u30d7\u3067\u3001\u3059\u3079\u3066\u306e\u7d44\u307f\u5408\u308f\u305b\u306b\u5bfe\u3057\u3066\u305d\u308c\u305e\u308c\u5408\u8a08\u3092\u6c42\u3081\u308b\u3002<\/p>\n\n\n\n<p>\u6b21\u306b\u3001\u7247\u65b9\u306e\u30b0\u30eb\u30fc\u30d7\u304b\u3089 k \u3092\u5f15\u3044\u305f\u5024 \u3092\u6c42\u3081\u308b\u3002<br>\u305d\u306e\u5024\u304c\u3082\u3046\u4e00\u65b9\u306e\u30b0\u30eb\u30fc\u30d7\u306e\u5408\u8a08\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3092\u8abf\u3079\u308b\u3002<\/p>\n\n\n\n<p>\uff08\u6587\u7ae0\u3058\u3083\u4f1d\u308f\u308a\u305a\u3089\u3044\u3088\u306d\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq;\nusing System.Collections.Generic;\nclass Program\n{\n    static void Main(string&#91;] args)\n    {\n        bool result = Solve();\n        if (result) Console.WriteLine(\"Yes\");\n        else Console.WriteLine(\"No\");\n    }\n\n    private static bool Solve()\n    {\n        int&#91;] nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int n = nk&#91;0];\n        int k = nk&#91;1];\n        int&#91;] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] b = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] c = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();\n        int&#91;] abSum = new int&#91;n * n];\n        int&#91;] cdSum = new int&#91;n * n];\n        Dictionary&lt;int, bool> map = new Dictionary&lt;int, bool>();\n\n        int index = 0;\n        for (int f = 0; f &lt; n; f++)\n        {\n            for (int s = 0; s &lt; n; s++)\n            {\n                abSum&#91;index] = a&#91;f] + b&#91;s];\n                cdSum&#91;index] = c&#91;f] + d&#91;s];\n                index++;\n            }\n        }\n\n        for (int f = 0; f &lt; cdSum.Length; f++)\n        {\n            map&#91;cdSum&#91;f]] = true;\n        }\n\n        for (int f = 0; f &lt; abSum.Length; f++)\n        {\n            int target = k - abSum&#91;f];\n            if (map.ContainsKey(target))\n            {\n                if (map&#91;target] == true) return true;\n            }\n        }\n\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u30b0\u30eb\u30fc\u30d7AB\u3068\u30b0\u30eb\u30fc\u30d7CD\u306f\u8981\u7d20\u6570\u304cn\u306a\u306e\u3067\u30011\u30b0\u30eb\u30fc\u30d7\u306b\u5bfe\u3057\u3066\u5168\u7d44\u307f\u5408\u308f\u305b\u306fn*n\u3002\u8a08\u7b97\u91cf\u306f\u6700\u5927\u3067n\u306e2\u4e57\u30022\u30b0\u30eb\u30fc\u30d7\u306a\u306e\u30672n\u306e2\u4e57\u3002<\/p>\n\n\n\n<p>Dictionary&lt;int, bool>\u306bKey\u304ck-cdi(1&lt;=i&lt;=n)\u3092true\u306b\u3057\u3066\u3001\u3053\u308c\u304c\u30b0\u30eb\u30fc\u30d7AB\u306e\u7d44\u307f\u5408\u308f\u305b\u306b\u542b\u307e\u308c\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3002\u8a08\u7b97\u91cf\u306f10\u306e6\u4e57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u554f\u984c A14 &#8211; Four Boxes \u8003\u3048\u65b9 \u554f\u984c\u6587\u3092\u7406\u89e3\u3059\u308b\u3002 A\u3001B\u3001C\u3001D4\u3064\u306e\u6570\u5217\u304c\u4e0e\u3048\u3089\u308c\u308b\u306e\u3067\u3001\u5404\u6570\u5217\u304b\u30891\u3064\u305a\u3064\u5024\u3092\u9078\u3093\u3067\u5408\u7b97\u3057\u305f\u5024\u304ck\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308b\u304b\u3092\u554f\u308f\u308c\u3066\u3044\u308b\u3002 \u89e3\u8aac \u307e\u305a\u306f\u5168\u63a2\u7d22\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/3023"}],"collection":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3023"}],"version-history":[{"count":3,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/3023\/revisions"}],"predecessor-version":[{"id":3026,"href":"https:\/\/histy.jp\/index.php?rest_route=\/wp\/v2\/posts\/3023\/revisions\/3026"}],"wp:attachment":[{"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/histy.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}