{"id":4594,"date":"2018-12-27T19:03:34","date_gmt":"2018-12-27T16:03:34","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4594"},"modified":"2018-12-27T19:41:24","modified_gmt":"2018-12-27T16:41:24","slug":"e-olymp-1489-%d1%88%d0%be%d0%ba%d0%be%d0%bb%d0%b0%d0%b4","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4594","title":{"rendered":"e-olymp 1489. \u0428\u043e\u043a\u043e\u043b\u0430\u0434"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u041f\u0435\u0442\u044f \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434. \u0418 \u041c\u0430\u0448\u0430 \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u041f\u0435\u0442\u044f \u043a\u0443\u043f\u0438\u043b \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0435\u044e \u0441 \u041c\u0430\u0448\u0435\u0439. \u0428\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a $n \\cdot m$, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445\u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u043a \u2014 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432 $2 \\cdot 1$.\u00a0 \u00a0 \u00a0 \u00a0<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4598 alignright\" src=\"http:\/\/java.mazurok.com\/wp-content\/uploads\/\u0448\u043e\u043a\u043e\u043b\u0430\u0434-\u0438\u043b\u044c\u0438.jpg\" alt=\"\" width=\"297\" height=\"155\" \/><\/p>\n<p>\u041f\u0435\u0442\u044f \u0434\u0435\u043b\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438, \u0440\u0430\u0437\u043b\u0430\u043c\u044b\u0432\u0430\u044f \u0435\u0435 \u0432\u0434\u043e\u043b\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u043a\u0440\u0430\u0435\u0432 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0438. \u041d\u0438 \u041f\u0435\u0442\u044f, \u043d\u0438 \u041c\u0430\u0448\u0430 \u043d\u0435 \u043b\u044e\u0431\u044f\u0442 \u043b\u043e\u043c\u0430\u043d\u044b\u0435 \u0434\u043e\u043b\u044c\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u041f\u0435\u0442\u044f \u0445\u043e\u0447\u0435\u0442 \u0440\u0430\u0437\u043b\u043e\u043c\u0430\u0442\u044c \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0438 \u043e\u0434\u043d\u0430 \u0434\u043e\u043b\u044c\u043a\u0430 \u043d\u0435 \u0431\u044b\u043b\u0430 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0430.<\/p>\n<p>\u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u041f\u0435\u0442\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u043e\u0439 \u0441 \u041c\u0430\u0448\u0435\u0439.<\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 $n$ \u0438 $m$ ($1 \\le n, m \\le 20$, \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0438\u0437 \u0447\u0438\u0441\u0435\u043b $n$ \u0438 $m$ \u2014 \u0447\u0435\u0442\u043d\u043e). \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 $n$ \u0441\u0442\u0440\u043e\u043a \u043f\u043e $m$ \u0447\u0438\u0441\u0435\u043b \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u2014 \u043d\u043e\u043c\u0435\u0440\u0430 \u0434\u043e\u043b\u0435\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u0443\u0441\u043e\u0447\u043a\u0438 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0438. \u0414\u043e\u043b\u044c\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u043d\u043e\u043c\u0435\u0440\u0430 \u043e\u0442 $1$ \u0434\u043e $\\frac{n \\cdot m}{2}$, \u0438 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0432\u0435 \u0434\u043e\u043b\u044c\u043a\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043d\u043e\u043c\u0435\u0440\u0430.<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0430\u0439\u043b \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u00ab$Yes$\u00bb, \u0435\u0441\u043b\u0438 \u041f\u0435\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043b\u043e\u043c\u0430\u0442\u044c \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443, \u043d\u0435 \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0432 \u0434\u043e\u043b\u044c\u043a\u0438. \u0418\u043d\u0430\u0447\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u00ab$No$\u00bb.<\/p>\n<p><strong>TESTS<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<th>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<th>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">2 3<br \/>\n1 1 2<br \/>\n3 3 2<\/td>\n<td style=\"text-align: center\">Yes<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">5 6<br \/>\n1 2 2 3 3 4<br \/>\n1 5 6 7 7 4<br \/>\n8 5 6 9 10 10<br \/>\n8 11 11 9 12 13<br \/>\n14 14 15 15 12 13<\/td>\n<td style=\"text-align: center\">No<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left\">4 7<br \/>\n1 1 2 5 8 11 6<br \/>\n2 14 4 7 3 9 5<br \/>\n3 7 10 6 13 2 3<br \/>\n4 3 8 12 5 7 7<\/td>\n<td style=\"text-align: center\">Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h1>\n<pre class=\"lang:java decode:true \">import java.io.InputStream;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n    public static void main(String[] args) {\r\n        new Resolver(System.in, System.out).solve();\r\n    }\r\n\r\n    public static class Resolver {\r\n\r\n        private Scanner scanner;\r\n        private PrintWriter writer;\r\n\r\n        public Resolver(InputStream is, OutputStream os) {\r\n            this.scanner = new Scanner(is);\r\n            this.writer = new PrintWriter(os);\r\n        }\r\n\r\n        public void solve() {\r\n            int rowCount = scanner.nextInt();\r\n            int columnCount = scanner.nextInt();\r\n            int[][] chocolate = new int[rowCount][columnCount];\r\n            for (int i = 0; i &lt; rowCount; i++) {\r\n                for (int j = 0; j &lt; columnCount; j++) chocolate[i][j] = scanner.nextInt();\r\n            }\r\n            check(chocolate, rowCount, columnCount);\r\n            writer.flush(); writer.close();\r\n        }\r\n\r\n        private void check(int[][] chocolate, int rowCount, int columnCount) {\r\n            if (BreakRow(chocolate, rowCount, columnCount) || BreakColumn(chocolate, rowCount, columnCount)) writer.println(&quot;Yes&quot;);\r\n            else writer.println(&quot;No&quot;);\r\n        }\r\n        private boolean BreakRow(int[][] chocolate, int rowCount, int columnCount) {\r\n            for (int i = 0; i &lt; rowCount - 1; i++) {\r\n                boolean okRow = true;\r\n                for (int j = 0; j &lt; columnCount; j++) {\r\n                    if (chocolate[i][j] == chocolate[i + 1][j]) { okRow = false; break; }\r\n                }\r\n                if (okRow) return true;\r\n            }\r\n            return false;\r\n        }\r\n        private boolean BreakColumn(int[][] chocolate, int rowCount, int columnCount) {\r\n            for (int i = 0; i &lt; columnCount - 1; i++) {\r\n                boolean okColumn = true;\r\n                for (int j = 0; j &lt; rowCount; j++) {\r\n                    if (chocolate[j][i] == chocolate[j][i + 1]) { okColumn = false; break; }\r\n                }\r\n                if (okColumn) return true;\r\n            }\r\n            return false;\r\n        }\r\n    }\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u043a\u0430\u043a \u0434\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0440\u0430\u0437\u043b\u043e\u043c\u0430\u0442\u044c \u043f\u043b\u0438\u0442\u043a\u0443 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u0430 \u0440\u043e\u0432\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u00ab\u0441\u0442\u0440\u043e\u043a\u00bb \u0438 \u00ab\u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432\u00bb \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u0430. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code> \u0438 <code>false<\/code> \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>BreakRow<\/code> \u0438 <code>BreakColumn<\/code> \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u0438\u043f\u0430 <code>boolean<\/code>. \u0417\u0430\u0442\u0435\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code>, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p><a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/1489\" target=\"_blank\" rel=\"noopener\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 E-olymp<\/a><br \/>\n<a href=\"https:\/\/ideone.com\/Dv9Jxb\" target=\"_blank\" rel=\"noopener\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041f\u0435\u0442\u044f \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434. \u0418 \u041c\u0430\u0448\u0430 \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434. \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u041f\u0435\u0442\u044f \u043a\u0443\u043f\u0438\u043b \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0435\u044e \u0441 \u041c\u0430\u0448\u0435\u0439. \u0428\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a $n \\cdot m$, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445\u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043d\u044b\u0445 \u0434\u043e\u043b\u0435\u043a \u2014 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432 $2 \\cdot 1$.\u00a0 \u00a0 \u00a0 \u00a0 \u041f\u0435\u0442\u044f \u0434\u0435\u043b\u0438\u0442 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u0443 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438, \u0440\u0430\u0437\u043b\u0430\u043c\u044b\u0432\u0430\u044f \u0435\u0435 \u0432\u0434\u043e\u043b\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0434\u043d\u043e\u043c\u0443 &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4594\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":125,"featured_media":4608,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,26],"tags":[636,326,71,219],"jetpack_featured_media_url":"https:\/\/java.mazurok.com\/wp-content\/uploads\/\u0448\u043e\u043a-1.jpg","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4594"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/125"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4594"}],"version-history":[{"count":2,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4594\/revisions"}],"predecessor-version":[{"id":4609,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4594\/revisions\/4609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/media\/4608"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}