Submission #5559407
Source Code Expand
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int R, C, N; struct point{ int r, c, id; }; int lev(point p){ if(p.r == 0) return 0; if(p.c == C) return 1; if(p.r == R) return 2; if(p.c == 0) return 3; return 4; } bool comp(point lhs, point rhs){ int levl = lev(lhs); int levr = lev(rhs); if(levl != levr) return levl < levr; if(levl == 0) return lhs.c < rhs.c; if(levl == 1) return lhs.r < rhs.r; if(levl == 2) return lhs.c > rhs.c; if(levl == 3) return lhs.r > rhs.r; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> R >> C >> N; vector<point> v; int id = 0; rep(i, N){ int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; point p1 = (point){x1, y1, id}; point p2 = (point){x2, y2, id}; if(lev(p1) < 4 && lev(p2) < 4){ v.push_back(p1); v.push_back(p2); id++; } } if(v.size() == 0){ cout << "YES" << endl; return 0; } sort(v.begin(), v.end(), comp); // rep(i, v.size()) cout << v[i].r << "," << v[i].c << "," << v[i].id << endl; stack<int> stc; set<int> st; for(int i = 0; i < v.size(); i++){ point p = v[i]; if(stc.size() == 0){ stc.push(p.id); st.insert(p.id); continue; } if(stc.top() == p.id){ stc.pop(); st.erase(p.id); continue; } auto itr = st.find(p.id); if(itr == st.end()){ stc.push(p.id); st.insert(p.id); }else{ cout << "NO" << endl; return 0; } } cout << "YES" << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Connected? |
User | misora192 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1573 Byte |
Status | AC |
Exec Time | 117 ms |
Memory | 5616 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 | 85 ms | 4212 KB |
02.txt | AC | 76 ms | 2932 KB |
03.txt | AC | 79 ms | 3060 KB |
04.txt | AC | 48 ms | 1148 KB |
05.txt | AC | 78 ms | 2932 KB |
06.txt | AC | 115 ms | 4976 KB |
07.txt | AC | 43 ms | 832 KB |
08.txt | AC | 84 ms | 3444 KB |
09.txt | AC | 52 ms | 1912 KB |
10.txt | AC | 91 ms | 4464 KB |
11.txt | AC | 79 ms | 3696 KB |
12.txt | AC | 37 ms | 256 KB |
13.txt | AC | 45 ms | 892 KB |
14.txt | AC | 53 ms | 2036 KB |
15.txt | AC | 62 ms | 2292 KB |
16.txt | AC | 41 ms | 512 KB |
17.txt | AC | 39 ms | 384 KB |
18.txt | AC | 37 ms | 256 KB |
19.txt | AC | 48 ms | 1400 KB |
20.txt | AC | 101 ms | 4848 KB |
21.txt | AC | 58 ms | 1912 KB |
22.txt | AC | 65 ms | 2292 KB |
23.txt | AC | 78 ms | 4080 KB |
24.txt | AC | 88 ms | 5488 KB |
25.txt | AC | 117 ms | 5360 KB |
26.txt | AC | 91 ms | 5360 KB |
27.txt | AC | 109 ms | 5616 KB |
28.txt | AC | 91 ms | 5488 KB |
29.txt | AC | 112 ms | 5616 KB |
30.txt | AC | 117 ms | 5104 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 |