{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eYou are given an \u003cspan class\u003d\"tex2jax_process\"\u003e$r\\! \\times\n \\! c$\u003c/span\u003e grid. Each cell of this grid is filled with a\n number between \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$r{\\cdot }c$\u003c/span\u003e inclusive,\n and each cell’s number is distinct.\u003c/p\u003e\n \u003cp\u003eDefine a grid of numbers to be \u003ci class\u003d\"itshape\"\u003emonotonic\u003c/i\u003e if each row and column is either\n increasing or decreasing (this can be different for each row or\n column).\u003c/p\u003e\n \u003cp\u003eDefine a \u003ci class\u003d\"itshape\"\u003esubgrid\u003c/i\u003e of the grid as\n follows: First choose some nonempty subset of the rows and\n columns. Next, take elements that lie in both the chosen rows\n and columns in the same order.\u003c/p\u003e\n \u003cp\u003eThere are \u003cspan class\u003d\"tex2jax_process\"\u003e$(2^ r{-}1)(2^\n c{-}1)$\u003c/span\u003e nonempty subgrids of the given grid. Of these\n subgrids, count how many are monotonic.\u003c/p\u003e\n \u003cp\u003eConsider this grid:\u003c/p\u003e\n \u003ccenter\u003e\n \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$2$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$5$\u003c/span\u003e\u003cbr\u003e\n \u003cspan class\u003d\"tex2jax_process\"\u003e$7$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$6$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$4$\u003c/span\u003e\u003cbr\u003e\n \u003cspan class\u003d\"tex2jax_process\"\u003e$9$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$8$\u003c/span\u003e \u003cspan class\u003d\"tex2jax_process\"\u003e$3$\u003c/span\u003e\u003cbr\u003e\n \u003c/center\u003e\n \u003cp\u003eThere are nine \u003cspan class\u003d\"tex2jax_process\"\u003e$1{\\times\n }1$\u003c/span\u003e subgrids, nine \u003cspan class\u003d\"tex2jax_process\"\u003e$1{\\times }2$\u003c/span\u003e’s, three \u003cspan class\u003d\"tex2jax_process\"\u003e$1{\\times }3$\u003c/span\u003e’s, nine \u003cspan class\u003d\"tex2jax_process\"\u003e$2{\\times }1$\u003c/span\u003e’s, nine \u003cspan class\u003d\"tex2jax_process\"\u003e$2{\\times }2$\u003c/span\u003e’s, three \u003cspan class\u003d\"tex2jax_process\"\u003e$2{\\times }3$\u003c/span\u003e’s, three \u003cspan class\u003d\"tex2jax_process\"\u003e$3{\\times }1$\u003c/span\u003e’s, three \u003cspan class\u003d\"tex2jax_process\"\u003e$3{\\times }2$\u003c/span\u003e’s, and one \u003cspan class\u003d\"tex2jax_process\"\u003e$3{\\times }3$\u003c/span\u003e. They are all monotonic,\n for \u003cspan class\u003d\"tex2jax_process\"\u003e$9{+}9{+}3{+}9{+}9{+}3{+}3{+}3{+}1\u003d49$\u003c/span\u003e\n monotonic subgrids.\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eEach test case will begin with a line with two\n space-separated integers \u003cspan class\u003d\"tex2jax_process\"\u003e$r$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$c$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\\! \\le \\! r,c\\! \\le \\! 20$\u003c/span\u003e), which\n are the dimensions of the grid.\u003c/p\u003e\n \u003cp\u003eEach of the next \u003cspan class\u003d\"tex2jax_process\"\u003e$r$\u003c/span\u003e\n lines will contain \u003cspan class\u003d\"tex2jax_process\"\u003e$c$\u003c/span\u003e\n space-separated integers \u003cspan class\u003d\"tex2jax_process\"\u003e$x$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\\! \\le \\! x\\! \\le \\! r{\\cdot }c$\u003c/span\u003e,\n all \u003cspan class\u003d\"tex2jax_process\"\u003e$x$\u003c/span\u003e’s are unique).\n This is the grid.\u003c/p\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eOutput a single integer, which is the number of monotonic\n subgrids in the given grid.\u003c/p\u003e\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 3\n1 2 5\n7 6 4\n9 8 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e49\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 3\n8 2 5\n12 9 6\n3 1 10\n11 7 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e64\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}