Submission #2118832


Source Code Expand

//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n, w, h;
vector<pair<int, int> > v[6];
bool border(int x, int y){
	if(x == 0 || x == h || y == 0 || y == w)
		return 1;
	return 0;
}
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> h >> w >> n;
	for(int i = 1; i <= n; i ++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if(!border(x1, y1) || !border(x2, y2))
			continue;
		if(x1 == 0){
			v[1].pb(mp(y1, i));
		}else
		if(y1 == w){
			v[2].pb(mp(x1, i));
		}else
		if(x1 == h)
			v[3].pb(mp(y1, i));
		else
		if(y1 == 0)
			v[4].pb(mp(x1, i));
		if(x2 == 0){
			v[1].pb(mp(y2, i));
		}else
		if(y2 == w){
			v[2].pb(mp(x2, i));
		}else
		if(x2 == h)
			v[3].pb(mp(y2, i));
		else
		if(y2 == 0)
			v[4].pb(mp(x2, i));
	}	
	stack<int> s;
	sort(v[1].beg(), v[1].end());
	sort(v[2].beg(), v[2].end());    
	sort(v[3].beg(), v[3].end());    
	sort(v[4].beg(), v[4].end());
	reverse(v[3].beg(), v[3].end());
	reverse(v[4].beg(), v[4].end());
	for(int i = 0; i < v[1].sz(); i ++){
		if(s.sz() && s.top() == v[1][i].S){
			s.pop();
		}else
			s.push(v[1][i].S);
	}
	for(int i = 0; i < v[2].sz(); i ++){
		if(s.sz() && s.top() == v[2][i].S){
			s.pop();
		}else
			s.push(v[2][i].S);
	}
	for(int i = 0; i < v[3].sz(); i ++){
		if(s.sz() && s.top() == v[3][i].S){
			s.pop();
		}else
			s.push(v[3][i].S);
	}
	for(int i = 0; i < v[4].sz(); i ++){
		if(s.sz() && s.top() == v[4][i].S){
			s.pop();
		}else
			s.push(v[4][i].S);
	}
	if(s.sz() > 0)
		cout << "NO";
	else
		cout << "YES";
	return 0;
}

Submission Info

Submission Time
Task E - Connected?
User l_love_KFC
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2453 Byte
Status AC
Exec Time 56 ms
Memory 2520 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 4
AC × 38
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 48 ms 1464 KB
02.txt AC 47 ms 1364 KB
03.txt AC 47 ms 1528 KB
04.txt AC 41 ms 836 KB
05.txt AC 47 ms 1272 KB
06.txt AC 53 ms 2416 KB
07.txt AC 42 ms 512 KB
08.txt AC 49 ms 1628 KB
09.txt AC 44 ms 1016 KB
10.txt AC 52 ms 2036 KB
11.txt AC 50 ms 1608 KB
12.txt AC 38 ms 256 KB
13.txt AC 40 ms 640 KB
14.txt AC 43 ms 1224 KB
15.txt AC 46 ms 1188 KB
16.txt AC 40 ms 384 KB
17.txt AC 39 ms 256 KB
18.txt AC 38 ms 256 KB
19.txt AC 42 ms 896 KB
20.txt AC 53 ms 2520 KB
21.txt AC 44 ms 976 KB
22.txt AC 45 ms 1232 KB
23.txt AC 54 ms 2188 KB
24.txt AC 53 ms 2200 KB
25.txt AC 55 ms 2096 KB
26.txt AC 56 ms 2520 KB
27.txt AC 54 ms 2096 KB
28.txt AC 52 ms 2200 KB
29.txt AC 54 ms 2108 KB
30.txt AC 54 ms 2108 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