Submission #524582


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) os << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 0) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
template <typename T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
#define dump(v) (cout << #v << ": " << v << endl)

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
    int n;
    cin >> n;
    int m = 2 * n + 1;

    static vector<int> xs[2 * 114514], ys[2 * 114514];
    vector<pint> ps;
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        ps.push_back(pint(x, y));

        xs[y].push_back(x);
        ys[x].push_back(y);
    }

    map<pint, bool> dp;
    queue<pair<pint, bool>> q;
    q.push(make_pair(ps.back(), 0));
    while (!q.empty())
    {
        pint pos = q.front().first;
        int cur_x, cur_y;
        tie(cur_x, cur_y) = q.front().first;
        bool pari = q.front().second;
        q.pop();
//         dump(make_pair(pint(cur_x, cur_y), pari));

        if (dp.count(pint(pos)))
            continue;

        dp[pos] = true;

        for (int y : ys[cur_x])
            q.push(make_pair(pint(cur_x, y), pari ^ 1));
        for (int x : xs[cur_y])
            q.push(make_pair(pint(x, cur_y), pari ^ 1));
    }

    rep(i, m)
    {
        int x, y;
        tie(x, y) = ps[i];

        bool ok = dp[pint(x, y)] != (i & 1);
        cout << (ok ? "OK" : "NG") << endl;
    }
}

Submission Info

Submission Time
Task D - みんな仲良し高橋君
User takapt
Language C++11 (GCC 4.9.2)
Score 0
Code Size 4349 Byte
Status
Exec Time 3211 ms
Memory 1048576 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 30 0 / 70
Status
× 1
× 2
× 10
× 5
× 3
× 35
× 10
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
Subtask1 bone_bubun_0.txt, bone_bubun_1.txt, bone_bubun_2.txt, komakai_bubun_0.txt, komakai_bubun_1.txt, komakai_bubun_2.txt, maxrand_bubun_0.txt, maxrand_bubun_1.txt, random_bubun_0.txt, random_bubun_1.txt, smallrand_bubun_0.txt, smallrand_bubun_1.txt, smallrand_bubun_2.txt, square_bubun_0.txt, square_bubun_1.txt
All bone_0.txt, bone_1.txt, bone_2.txt, bone_bubun_0.txt, bone_bubun_1.txt, bone_bubun_2.txt, example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, handmade_2.txt, handmade_3.txt, komakai_0.txt, komakai_1.txt, komakai_2.txt, komakai_bubun_0.txt, komakai_bubun_1.txt, komakai_bubun_2.txt, maxrand_0.txt, maxrand_1.txt, maxrand_bubun_0.txt, maxrand_bubun_1.txt, random_0.txt, random_1.txt, random_bubun_0.txt, random_bubun_1.txt, renket_0.txt, renket_1.txt, smallrand_0.txt, smallrand_1.txt, smallrand_bubun_0.txt, smallrand_bubun_1.txt, smallrand_bubun_2.txt, square_0.txt, square_1.txt, square_bubun_0.txt, square_bubun_1.txt, supersmall_0.txt, supersmall_1.txt, threeren_0.txt, threeren_1.txt, treebase_0.txt, treebase_1.txt, treebase_2.txt, example_0.txt, example_1.txt, example_2.txt
Case Name Status Exec Time Memory
bone_0.txt 3211 ms 1048576 KB
bone_1.txt 3142 ms 987932 KB
bone_2.txt 3140 ms 993692 KB
bone_bubun_0.txt 3042 ms 1048576 KB
bone_bubun_1.txt 3091 ms 441824 KB
bone_bubun_2.txt 3087 ms 1048576 KB
example_0.txt 45 ms 11428 KB
example_1.txt 44 ms 11492 KB
example_2.txt 45 ms 11436 KB
handmade_0.txt 45 ms 11428 KB
handmade_1.txt 45 ms 11432 KB
handmade_2.txt 46 ms 11428 KB
handmade_3.txt 46 ms 11424 KB
komakai_0.txt 1451 ms 33188 KB
komakai_1.txt 1337 ms 32464 KB
komakai_2.txt 1466 ms 33172 KB
komakai_bubun_0.txt 1308 ms 31772 KB
komakai_bubun_1.txt 1327 ms 32272 KB
komakai_bubun_2.txt 1334 ms 32272 KB
maxrand_0.txt 1130 ms 33428 KB
maxrand_1.txt 1111 ms 33432 KB
maxrand_bubun_0.txt 1431 ms 32916 KB
maxrand_bubun_1.txt 1534 ms 32920 KB
random_0.txt 77 ms 12200 KB
random_1.txt 592 ms 24260 KB
random_bubun_0.txt 88 ms 12320 KB
random_bubun_1.txt 409 ms 17688 KB
renket_0.txt 1516 ms 32784 KB
renket_1.txt 1516 ms 32904 KB
smallrand_0.txt 48 ms 11480 KB
smallrand_1.txt 47 ms 11452 KB
smallrand_bubun_0.txt 44 ms 11480 KB
smallrand_bubun_1.txt 46 ms 11424 KB
smallrand_bubun_2.txt 46 ms 11432 KB
square_0.txt 3134 ms 926516 KB
square_1.txt 3131 ms 924460 KB
square_bubun_0.txt 3132 ms 935720 KB
square_bubun_1.txt 3132 ms 913408 KB
supersmall_0.txt 46 ms 11428 KB
supersmall_1.txt 48 ms 11424 KB
threeren_0.txt 1275 ms 30928 KB
threeren_1.txt 1351 ms 30864 KB
treebase_0.txt 1408 ms 32528 KB
treebase_1.txt 323 ms 16540 KB
treebase_2.txt 1062 ms 27544 KB