-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fb6a2c
commit aa8494e
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Date: Fri Apr 14 23:48:56 2023 | ||
|
||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; | ||
const double eps = 1e-8; | ||
const int dir[8][2] = { | ||
{0, 1}, {0, -1}, | ||
{1, 0}, {-1, 0}, | ||
{1, 1}, {1, -1}, | ||
{-1, 1}, {-1, -1}, | ||
}; | ||
|
||
typedef long long ll; | ||
typedef unsigned long long ull; | ||
typedef vector<int> VI; | ||
typedef pair<int, int> PII; | ||
|
||
const ull Pr = 131; | ||
|
||
#define LN ListNode | ||
#define LNP ListNode* | ||
#define TN TreeNode | ||
#define TNP TreeNode* | ||
|
||
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i) | ||
#define PER(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) | ||
#define REP1(i, a, b) for (int i = int(a); i <= int(b); ++i) | ||
#define PER1(i, a, b) for (int i = int(b); i >= int(a); --i) | ||
#define REPE(i, j) for (int i = h[j]; i != -1; i = ne[i]) | ||
|
||
#define f1 first | ||
#define f2 second | ||
#define pb push_back | ||
#define has(a, x) (a.find(x) != a.end()) | ||
#define nonempty(a) (!a.empty()) | ||
#define all(a) (a).begin(),(a).end() | ||
#define SZ(a) int((a).size()) | ||
|
||
#ifdef _DEBUG | ||
#define debug1(x) cout << #x" = " << x << endl; | ||
#define debug2(x,y) cout << #x" = " << x << " "#y" = " << y << endl; | ||
#define debug3(x,y,z) cout << #x" = " << x << " "#y" = " << y << " "#z" = " << z << endl; | ||
#else | ||
#define debug1 | ||
#define debug2 | ||
#define debug3 | ||
#endif | ||
|
||
#ifdef _DEBUG | ||
|
||
struct ListNode { | ||
int val; | ||
ListNode *next; | ||
ListNode() : val(0), next(nullptr) {} | ||
ListNode(int val) : val(val), next(nullptr) {} | ||
ListNode(int val, ListNode *next) : val(val), next(next) {} | ||
}; | ||
|
||
struct TreeNode { | ||
int val; | ||
TreeNode *left; | ||
TreeNode *right; | ||
TreeNode() : val(0), left(nullptr), right(nullptr) {} | ||
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | ||
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | ||
}; | ||
|
||
#endif | ||
|
||
bool check(int n) { | ||
if (n == 1) return false; | ||
|
||
for (int j = 2; j * j <= n; ++j) { | ||
if (n % j == 0) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
class Solution { | ||
public: | ||
int diagonalPrime(vector<vector<int>>& a) { | ||
int n = SZ(a), res = 0; | ||
|
||
REP(i, 0, n) { | ||
if (check(a[i][i]) && a[i][i] > res) res = a[i][i]; | ||
} | ||
|
||
REP(i, 0, n) { | ||
int x = a[i][n - i - 1]; | ||
if (check(x) && x > res) res = x; | ||
} | ||
|
||
return res; | ||
} | ||
}; |