{"problem":{"name":"F. Flipping El-fetiera","description":{"content":"Fouad was craving for Fetiera, so he went to a Fetier restaurant and ordered one. The chef told him that he sells a square Fetiera in the form of a N × N matrix. On the surface of the Fetiera, there ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":10000,"memory_limit":1048576},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10199F"},"statements":[{"statement_type":"Markdown","content":"Fouad was craving for Fetiera, so he went to a Fetier restaurant and ordered one. The chef told him that he sells a square Fetiera in the form of a N × N matrix.\n\nOn the surface of the Fetiera, there is one Semsema on each 1 × 1 cell of the Fetiera. Each Semsema can be either on the top side or the bottom side of the Fetira, but he cannot have two Semsemas in one cell on both sides.\n\nFouad loves to watch the chef flipping Fetiera, and this one was way more interesting than usual. The chef chooses a random (uniformly at random) rectangular submatrix and flips it in place. Whenever he flips a submatrix of the Fetira, the Semsemas which were on top will be on the bottom and vice versa.\n\nGiven the initial state of the Fetiera, and knowing that the chef did the flipping K times, Fouad was wondering how many Semsemas will be on the top side of it. Therefore, he is asking you to help him find the expected number of Semsemas on the top side.\n\nThe first line of input contains a single integer T specifying the number of test cases. \n\nEach test case begins with a line containing two space-separated integers N and K (1 ≤ N ≤ 300, 0 ≤ K ≤ 300), in which N is the size of the Fetiera matrix, and K is the number of flipping operations.\n\nThen N lines follow, each line i contains N space-separated values Fi1, ..., FiN (), in which Fij representing the top side of the jth cell in the ith row of the Fetiera (1 means the Semsema is on the top side and 0 means the Semsema is on the bottom side in the initial configuration).\n\nFor each test case, print a single line containing a single decimal number (rounded to exactly 5 decimal places) representing the expected number of Semsemas on the Fetiera after making the flipping operation for exactly K times. The output will be checked with a relative error.\n\n## Input\n\nThe first line of input contains a single integer T specifying the number of test cases. Each test case begins with a line containing two space-separated integers N and K (1 ≤ N ≤ 300, 0 ≤ K ≤ 300), in which N is the size of the Fetiera matrix, and K is the number of flipping operations.Then N lines follow, each line i contains N space-separated values Fi1, ..., FiN (), in which Fij representing the top side of the jth cell in the ith row of the Fetiera (1 means the Semsema is on the top side and 0 means the Semsema is on the bottom side in the initial configuration).\n\n## Output\n\nFor each test case, print a single line containing a single decimal number (rounded to exactly 5 decimal places) representing the expected number of Semsemas on the Fetiera after making the flipping operation for exactly K times. The output will be checked with a relative error.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let:  \n- $ N \\in \\mathbb{Z}_{\\geq 0} $: average goals per match in last season,  \n- $ M \\in \\mathbb{Z}_{\\geq 0} $: goals scored so far this season,  \n- $ X \\in \\mathbb{Z}_{>0} $: matches already played this season,  \n- $ Y \\in \\mathbb{Z}_{\\geq 0} $: remaining matches this season.  \n\n**Constraints**  \n1. $ 0 \\leq N, M, X, Y \\leq 100 $  \n2. $ X + Y > 0 $  \n\n**Objective**  \nCompute the minimum number of goals $ g \\in \\mathbb{Z}_{\\geq 0} $ to score in the remaining $ Y $ matches such that:  \n$$\n\\frac{M + g}{X + Y} \\geq N\n$$  \nIf no such $ g $ exists (i.e., even scoring $ Y $ goals is insufficient), output $ -1 $.  \n\nEquivalently, solve for minimum $ g $ satisfying:  \n$$\ng \\geq N(X + Y) - M\n$$  \nwith $ 0 \\leq g \\leq Y $.  \nIf $ N(X + Y) - M > Y $, output $ -1 $.  \nOtherwise, output $ \\max(0, \\lceil N(X + Y) - M \\rceil) $.  \n\nSince all values are integers:  \n$$\ng_{\\text{min}} = \\max\\left(0, N(X + Y) - M\\right)\n$$  \nif $ g_{\\text{min}} \\leq Y $, else $ -1 $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10199F","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}