#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; pair<double, double> need[500][500]; void solve() { int n, m, l, r; while (scanf("%lld%lld%lld%lld", &n, &m, &l, &r) == 4) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int tmp; scanf("%lld", &tmp); need[i][j] = make_pair(1.0 * l / tmp, 1.0 * r / tmp); } } bool flag = true; for (int i = 0; i < n - 1; ++i) { pair<double, double> k, tmpk; k = make_pair(need[i + 1][0].first / need[i][0].second, need[i + 1][0].second / need[i][0].first); for (int j = 1; j < m; ++j) { tmpk = make_pair(need[i + 1][j].first / need[i][j].second, need[i + 1][j].second / need[i][j].first); k = make_pair(max(k.first, tmpk.first), min(k.second, tmpk.second)); if (k.first > k.second) { flag = false; break; } } if (!flag) break; } if (!flag) puts("NO"); else puts("YES"); } } signed main() { // ios_base::sync_with_stdio(false); // cin.tie(nullptr); // cout.tie(nullptr); #ifdef ACM_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); signed localTestCount = 1, localReadPos = cin.tellg(); char localTryReadChar; do { if (localTestCount > 20) throw runtime_error("Check the stdin!!!"); auto startClockForDebug = clock(); solve(); auto endClockForDebug = clock(); cout << "Test " << localTestCount << " successful" << endl; cerr << "Test " << localTestCount++ << " Run Time: " << double(endClockForDebug - startClockForDebug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } while (localReadPos != cin.tellg() && cin >> localTryReadChar && localTryReadChar != '$' && cin.putback(localTryReadChar)); #else solve(); #endif return 0; } |
Double click to view unformatted code.