Untitled
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); // X // 1 2 3 4 ... X (X + 1) (X + 2) .... 1e9 // T T T T ... T F F FFFF F } // X can be 1 2 3 4 5 6 7 8 9 // T T T F F F F F F // X = // 2 1 3 // 4 2 4 // 5 9 6 // Rows - (2, 3) > 0 // Columns - (1, 3) > 0 // bool isValid(int X, int mat[][]) { // check if there at least one // } /* 1e8 = 1s // 1e9 // 30 3 * 1e7 = 1e14 100,000,000,000,000,000 // 10 seconds FOR X = [1...1e9]: IF isValid(X, Mat) is true: index++; ELSE: X = index - 1; break; PRINT(X) O(validRows) + O(validColumns) = N * M + N * M = N * M bool isValid(X, Mat) { ROWS = validRows(X, Mat); COLUMNS = validColumns(X, Mat); IF ROWS.Length > 0 AND COLUMNS.Length > 0: return true; Else return false; } N * O(isValidRow) = N * M int[] validRows(X, Mat) { int N = Mat.rowsLength ArrayInts rows = [] For i = [1...N]: If isValidRow(X, i, Mat): rows.push(i); i++; Else: i++; return rows; } M bool isValidRow(X, i, Mat) { int M = Mat.colsLength For j = [1...M]: If Mat[i][j] >= X: j++; Else: return false; return true; } */
Leave a Comment