Submission #11477381


Source Code Expand

#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;

typedef struct {
	int x;
	int y;
	int w;
} Loc;

Loc loc [ maxn << 1 ];
int col , row , n;
int x_1 , y_1 , x_2 , y_2 , cnt;
stack < int > ss;

inline int read ( )
{
	int s = 0 , t = 1; char ch = getchar ( );
	while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) t = -1; ch = getchar ( ); }
	while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ( ); }
	return s * t;
}

struct Rude1 {
	bool operator ( ) ( const Loc & s1 , const Loc & s2 ) const {
		return s1.x < s2.x;
	}
};

int cha ( int a , int b ) 
{
	if ( a == 0 ) return b;
	else if ( b == col ) return col + a;
	else if ( a == row ) return row + col + col - b;
	else if ( b == 0 ) return col * 2 + row * 2 - a;
	else return -1;
}

int main ( void )
{
	row = read ( ); col = read ( ); n = read ( );
	for ( int i = 0 ; i < n ; i++ ) {
		x_1 = read ( ); y_1 = read ( ); x_2 = read ( ); y_2 = read ( );
		int m = cha ( x_1 , y_1 ); int g = cha ( x_2 , y_2 );
		if ( m == -1 || g == -1 ) {
			continue;
		} 
		if ( m > g ) {
			swap ( m , g );
		}
		loc [ cnt ].w = 1;
		loc [ cnt ].x = m;
		loc [ cnt++ ].y = g;
		loc [ cnt ].w = 2;
		loc [ cnt ].x = g;
		loc [ cnt++ ].y = m;
		sort ( loc , loc + cnt , Rude1 ( ) );
		for ( int i = 0 ; i < cnt ; i++ ) {
			if ( loc [ i ].w == 1 ) {
				ss.push ( loc [ i ].y );
			} else if ( ss.top ( ) == loc [ i ].x ) {
				ss.pop ( );
			} else {
				puts ( "NO" );
				return 0;
			}
		}
	}
	puts ( "YES" );
	return 0;
}


Submission Info

Submission Time
Task E - Connected?
User vjudge1
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1538 Byte
Status TLE
Exec Time 2103 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 4
AC × 19
TLE × 19
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 TLE 2103 ms 384 KB
02.txt TLE 2103 ms 384 KB
03.txt TLE 2103 ms 384 KB
04.txt TLE 2103 ms 384 KB
05.txt TLE 2103 ms 384 KB
06.txt TLE 2103 ms 384 KB
07.txt AC 110 ms 256 KB
08.txt TLE 2103 ms 384 KB
09.txt AC 1605 ms 384 KB
10.txt TLE 2103 ms 384 KB
11.txt TLE 2103 ms 384 KB
12.txt AC 26 ms 256 KB
13.txt TLE 2103 ms 384 KB
14.txt TLE 2103 ms 384 KB
15.txt AC 87 ms 256 KB
16.txt AC 855 ms 384 KB
17.txt AC 81 ms 256 KB
18.txt AC 53 ms 256 KB
19.txt TLE 2103 ms 384 KB
20.txt AC 2 ms 256 KB
21.txt TLE 2103 ms 384 KB
22.txt AC 850 ms 384 KB
23.txt AC 46 ms 256 KB
24.txt AC 720 ms 384 KB
25.txt TLE 2103 ms 384 KB
26.txt TLE 2103 ms 384 KB
27.txt TLE 2103 ms 384 KB
28.txt TLE 2103 ms 384 KB
29.txt TLE 2103 ms 384 KB
30.txt TLE 2103 ms 384 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