Submission #39391605


Source Code Expand

#include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <climits>
#include <bitset>
//#include <bit>
//#include <tuple>
//#include <atcoder/modint>

namespace my_template
{
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = 1e9 + 1e6;
const ll LINF = 1e18 + 1e9;
//const int INF = INT32_MAX - 100;
//const ll LINF = LLONG_MAX - 100;
const int di[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}, dj[9] = {0, 1, 0, -1, -1, 1, -1, 1, 0};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define reprev(i, n) for (i = n - 1; i >= 0; i--)

#define cumsum(v, l, r) (l <= 0)? v[r - 1] : (v[r - 1] - v[l - 1])

#define lnprint(b) if (b){cout << endl;}else{cout << ' ';}

template <typename T>
T my_abs(T x){
    return (x >= 0) ? x : -x;
}

template <typename T>
bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

ll safe_mod(ll a, ll m){
    return (a % m + m) % m;
}

template<class S, class T>
void add(S &a, T b, int mod){
    assert(mod > 0);
    b = safe_mod(b, mod);
    a = (a + b) % mod;
}

ll extgcd(ll a, ll b, ll &p, ll &q){
    if (b == 0){
        p = 1;
        q = 0;
        return a;
    }
    ll d;
    d = extgcd(b, a % b, q, p);
    q -= a / b * p;
    return d;
}

ll gcd(ll a, ll b){
    ll p, q;
    return extgcd(a, b, p, q);
}

bool incld_bit(ll bit, int i){
    return ((bit >> i) & 1) == 1;
}

template<class T>
int my_popcount(T x, int dig = 100){
    int res;
    res = 0;
    while (x > 0 && dig > 0){
        res += (x&1);
        x >>= 1;
        dig--;
    }
    return res;
}

ll sttoint(string s){
    ll res;
    res = 0;
    for (char c: s){
        res = res * 10 + c - '0';
    }
    return res;
}

string inttost(ll x){
    string res;
    if (x == 0) return "0";
    while (x){
        res += '0' + x % 10;
        x /= 10;
    }
    reverse(res.begin(), res.end());
    return res;
}

double my_dist(P a, P b){
    ll dx, dy;
    dx = a.first - b.first;
    dy = a.second - b.second;
    return sqrt(dx * dx + dy * dy);
}

template<class T>
T multiset_max(multiset<T> &ms){
    assert(ms.empty() == false);
    auto back = ms.end();
    back--;
    return *back;
}

template<class T>
bool multiset_erase_one(multiset<T> &ms, T element){
    auto ite = ms.find(element);
    if (ite != ms.end()){
        ms.erase(ite);
        return true;
    }
    return false;
}

}

// --------------------------------------------------------------------------------

using namespace my_template;

int main(void){
    int i, j;
    int h, w, n;
    vector<int> x, y;

    cin >> h >> w >> n;
    x.resize(n);
    y.resize(n);
    rep0(i, n){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    set<P> ps, testps;
    const int dip[4] = {0, 0, 1, 1};
    const int djp[4] = {0, 1, 0, 1};
    rep0(i, n){
        ps.insert(P(x[i], y[i]));
        rep0(j, 4){
            int tx, ty;
            tx = x[i] - dip[j];
            ty = y[i] - djp[j];
            if (tx >= 0 && ty >= 0){
                testps.insert(P(tx, ty));
            }
        }
    }

    int ans;
    ans = 0;
    for (P p: testps){
        int tmp;
        int tx, ty;
        tmp = 0;
        tx = p.first;
        ty = p.second;
        rep0(j, 4){
            if (ps.find(P(tx + dip[j], ty + djp[j])) != ps.end()) tmp ^= 1;
        }
        ans += tmp;
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task C - Flip Grid
User Jupytor
Language C++ (GCC 9.2.1)
Score 200
Code Size 4221 Byte
Status AC
Exec Time 692 ms
Memory 51852 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 35
Set Name Test Cases
Sample 00_sample_01, 00_sample_02
All 00_sample_01, 00_sample_02, 01_randsmall_0, 01_randsmall_1, 01_randsmall_2, 01_randsmall_3, 01_randsmall_4, 02_randmid_0, 02_randmid_1, 02_randmid_2, 02_randmid_3, 02_randmid_4, 03_rand_0, 03_rand_1, 03_rand_2, 03_rand_3, 03_rand_4, 04_randmax_0, 04_randmax_1, 04_randmax_2, 04_randmax_3, 04_randmax_4, 05_rectangle_0, 05_rectangle_1, 05_rectangle_2, 05_rectangle_3, 05_rectangle_4, 06_unbalance_0, 06_unbalance_1, 06_unbalance_2, 06_unbalance_3, 06_unbalance_4, 10_corner_01, 10_corner_02, 10_corner_03
Case Name Status Exec Time Memory
00_sample_01 AC 7 ms 3580 KiB
00_sample_02 AC 3 ms 3460 KiB
01_randsmall_0 AC 2 ms 3528 KiB
01_randsmall_1 AC 2 ms 3468 KiB
01_randsmall_2 AC 2 ms 3472 KiB
01_randsmall_3 AC 2 ms 3464 KiB
01_randsmall_4 AC 2 ms 3420 KiB
02_randmid_0 AC 17 ms 4244 KiB
02_randmid_1 AC 16 ms 4608 KiB
02_randmid_2 AC 15 ms 4460 KiB
02_randmid_3 AC 8 ms 3988 KiB
02_randmid_4 AC 9 ms 4192 KiB
03_rand_0 AC 181 ms 17640 KiB
03_rand_1 AC 246 ms 22860 KiB
03_rand_2 AC 341 ms 28464 KiB
03_rand_3 AC 44 ms 7136 KiB
03_rand_4 AC 171 ms 17244 KiB
04_randmax_0 AC 673 ms 51812 KiB
04_randmax_1 AC 671 ms 51852 KiB
04_randmax_2 AC 672 ms 51612 KiB
04_randmax_3 AC 679 ms 51644 KiB
04_randmax_4 AC 692 ms 51696 KiB
05_rectangle_0 AC 204 ms 20048 KiB
05_rectangle_1 AC 162 ms 16844 KiB
05_rectangle_2 AC 204 ms 19884 KiB
05_rectangle_3 AC 621 ms 47072 KiB
05_rectangle_4 AC 214 ms 20504 KiB
06_unbalance_0 AC 458 ms 32420 KiB
06_unbalance_1 AC 435 ms 31484 KiB
06_unbalance_2 AC 444 ms 31500 KiB
06_unbalance_3 AC 391 ms 29372 KiB
06_unbalance_4 AC 544 ms 36652 KiB
10_corner_01 AC 2 ms 3376 KiB
10_corner_02 AC 3 ms 3580 KiB
10_corner_03 AC 2 ms 3380 KiB