Submission #5544168
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef pair<P, int> Pi; const int N = (int)1e5 + 50; int r, c; int n; vector<Pi> pts; int in[N]; int on_bound(int x, int y) { return x == 0 || x == r || y == 0 || y == c; } int bound(int x, int y) { if(x == 0 && y == 0) return 0; if(x == 0 && 0 < y && y < c) return 1; if(x == 0 && y == c) return 2; if(0 < x && x < r && y == c) return 3; if(x == r && y == c) return 4; if(x == r && 0 < y && y < c) return 5; if(x == r && y == 0) return 6; if(0 < x && x < r && y == 0) return 7; // cout << x << " " << y << endl; assert(false); } bool cmp(P p1, P p2) { int b1 = bound(p1.first, p1.second), b2 = bound(p2.first, p2.second); if(b1 != b2) return b1 < b2; if(b1 == 1) return p1.second < p2.second; if(b1 == 3) return p1.first < p2.first; if(b1 == 5) return p1.second > p2.second; if(b1 == 7) return p1.first > p2.first; } int main() { cin >> r >> c >> n; for(int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if(on_bound(x1, y1) && on_bound(x2, y2)) { pts.push_back({{x1, y1}, i}); pts.push_back({{x2, y2}, i}); } } sort(pts.begin(), pts.end(), [](const Pi &p1, const Pi &p2) { return cmp(p1.first, p2.first); }); stack<int> S; for(const auto &p : pts) { int cur = p.second; if(in[cur]) { if(!S.empty() && S.top() == cur) { S.pop(); in[cur] = false; } else { return cout << "NO" << endl, 0; } } else { in[cur] = true; S.push(cur); } } return cout << "YES" << endl, 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Connected? |
User | RobeZH |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1861 Byte |
Status | AC |
Exec Time | 194 ms |
Memory | 4980 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt, s4.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 43.txt, 44.txt, 45.txt, 46.txt, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 160 ms | 4852 KB |
02.txt | AC | 160 ms | 2036 KB |
03.txt | AC | 165 ms | 2036 KB |
04.txt | AC | 143 ms | 1148 KB |
05.txt | AC | 166 ms | 2036 KB |
06.txt | AC | 185 ms | 3444 KB |
07.txt | AC | 146 ms | 1020 KB |
08.txt | AC | 173 ms | 2292 KB |
09.txt | AC | 156 ms | 1912 KB |
10.txt | AC | 180 ms | 3444 KB |
11.txt | AC | 169 ms | 3444 KB |
12.txt | AC | 137 ms | 384 KB |
13.txt | AC | 143 ms | 1020 KB |
14.txt | AC | 154 ms | 1912 KB |
15.txt | AC | 154 ms | 1912 KB |
16.txt | AC | 145 ms | 832 KB |
17.txt | AC | 144 ms | 768 KB |
18.txt | AC | 138 ms | 640 KB |
19.txt | AC | 147 ms | 1272 KB |
20.txt | AC | 185 ms | 4980 KB |
21.txt | AC | 155 ms | 1912 KB |
22.txt | AC | 158 ms | 1912 KB |
23.txt | AC | 188 ms | 4468 KB |
24.txt | AC | 187 ms | 4340 KB |
25.txt | AC | 189 ms | 4724 KB |
26.txt | AC | 190 ms | 4084 KB |
27.txt | AC | 188 ms | 4340 KB |
28.txt | AC | 181 ms | 3444 KB |
29.txt | AC | 190 ms | 3444 KB |
30.txt | AC | 194 ms | 4468 KB |
43.txt | AC | 1 ms | 256 KB |
44.txt | AC | 1 ms | 256 KB |
45.txt | AC | 1 ms | 256 KB |
46.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | AC | 1 ms | 256 KB |
s4.txt | AC | 1 ms | 256 KB |