Submission #1380534


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int R, C, N;
//---------------------------------------------------------------------------------------------------
int parse(int x, int y) {
    if (y == 0) return x;
    else if (x == R) return R + y;
    else if (y == C) return R + C + (R - x);
    return 2 * R + C + (C - y);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> R >> C >> N;
    vector<pair<int, int>> v;
    rep(i, 0, N) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        if (a != 0 && a != R && b != 0 && b != C) continue;
        if (c != 0 && c != R && d != 0 && d != C) continue;
        v.push_back({ parse(a, b), i });
        v.push_back({ parse(c, d), i });
    }
    sort(v.begin(), v.end());

    stack<int> sta;
    for (auto p : v) {
        if (!sta.empty()) {
            if (sta.top() == p.second) sta.pop();
            else sta.push(p.second);
        }
        else sta.push(p.second);
    }

    if(sta.empty()) printf("YES\n");
    else printf("NO\n");
}

Submission Info

Submission Time
Task E - Connected?
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1938 Byte
Status AC
Exec Time 54 ms
Memory 2420 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 47 ms 2420 KB
02.txt AC 46 ms 1400 KB
03.txt AC 46 ms 1400 KB
04.txt AC 39 ms 892 KB
05.txt AC 47 ms 1400 KB
06.txt AC 53 ms 2420 KB
07.txt AC 39 ms 640 KB
08.txt AC 48 ms 1524 KB
09.txt AC 44 ms 1400 KB
10.txt AC 52 ms 2420 KB
11.txt AC 49 ms 2420 KB
12.txt AC 37 ms 256 KB
13.txt AC 40 ms 640 KB
14.txt AC 42 ms 1400 KB
15.txt AC 45 ms 1400 KB
16.txt AC 40 ms 512 KB
17.txt AC 38 ms 384 KB
18.txt AC 37 ms 256 KB
19.txt AC 41 ms 892 KB
20.txt AC 53 ms 2420 KB
21.txt AC 43 ms 1400 KB
22.txt AC 44 ms 1400 KB
23.txt AC 53 ms 2420 KB
24.txt AC 53 ms 2420 KB
25.txt AC 54 ms 2420 KB
26.txt AC 54 ms 2420 KB
27.txt AC 54 ms 2420 KB
28.txt AC 52 ms 2420 KB
29.txt AC 54 ms 2420 KB
30.txt AC 54 ms 2420 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