0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:08:47 +00:00

C - Zero Path

https://codeforces.com/contest/1695/submission/161141066
This commit is contained in:
Baoshuo Ren 2022-06-19 08:45:36 +08:00
parent c670d61a1d
commit c1e854a2f1
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

56
Codeforces/1695/C/C.cpp Normal file
View File

@ -0,0 +1,56 @@
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
std::vector<std::vector<int>>
g(n, std::vector<int>(m)),
f1(n, std::vector<int>(m)),
f2(n, std::vector<int>(m));
for (auto& e : g) {
for (auto& v : e) {
cin >> v;
}
}
f1[0][0] = f2[0][0] = g[0][0];
for (int i = 1; i < m; i++) {
f1[0][i] = f2[0][i] = f1[0][i - 1] + g[0][i];
}
for (int i = 1; i < n; i++) {
f1[i][0] = f2[i][0] = f1[i - 1][0] + g[i][0];
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
f1[i][j] = std::max(f1[i - 1][j], f1[i][j - 1]) + g[i][j];
f2[i][j] = std::min(f2[i - 1][j], f2[i][j - 1]) + g[i][j];
}
}
cout << (f1[n - 1][m - 1] % 2 == 0 && f1[n - 1][m - 1] >= 0 && f2[n - 1][m - 1] <= 0 ? "YES" : "NO") << endl;
}
return 0;
}