Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using ull = unsigned long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using pld = pair<ld, ld>;
- #define fi first
- #define se second
- #define pb push_back
- #define pf push_front
- #define mp make_pair
- #define ins insert
- #define sz(x) (int)(x.size());
- #define all(x) x.begin(), x.end()
- #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
- int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
- int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
- template<class X, class Y>
- bool minimize(X &x, const Y &y) {
- if (x > y)
- {
- x = y;
- return true;
- }
- return false;
- }
- template<class X, class Y>
- bool maximize(X &x, const Y &y) {
- if (x < y)
- {
- x = y;
- return true;
- }
- return false;
- }
- const int MOD = 1e9 + 7; //998244353
- template<class X, class Y>
- void add(X &x, const Y &y) {
- x = (x + y);
- if(x >= MOD) x -= MOD;
- }
- template<class X, class Y>
- void sub(X &x, const Y &y) {
- x = (x - y);
- if(x < 0) x += MOD;
- }
- /* Author : Le Ngoc Bao Anh, 11A5, LQD High School for Gifted Student*/
- const ll INF = 1e9;
- const int N = 1005;
- int cnt[N][N], f[N][N];
- bool visited[N][N][6];
- int Up[6], Down[6], Left[6], Right[6];
- pii state[6];
- void solve() {
- int a, b, c, n, m, k;
- cin >> a >> b >> c >> n >> m >> k;
- for(int i = 1; i <= k; i++) {
- int x, y; cin >> x >> y;
- cnt[x][y] = 1;
- }
- for(int i = 1; i <= n; i++) {
- for(int j = 1; j <= m; j++) {
- cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + cnt[i][j];
- }
- }
- auto ok = [&](int x, int y, int h, int w) -> bool {
- int u = x + h - 1, v = y + w - 1;
- if(x < 1 || y < 1 || u > n || v > m || h < 1 || w < 1) return false;
- int p = cnt[u][v] - cnt[x - 1][v] - cnt[u][y - 1] + cnt[x - 1][y - 1];
- return (p > 0 ? false : true);
- };
- auto goUp = [&](int &x, int &y, int &direct) -> bool {
- if(!ok(x - 1, y, state[direct].fi, state[direct].se)) return false;
- x--; return true;
- };
- auto goDown = [&](int &x, int &y, int &direct) -> bool {
- if(!ok(x + 1, y, state[direct].fi, state[direct].se)) return false;
- x++; return true;
- };
- auto goLeft = [&](int &x, int &y, int &direct) -> bool {
- if(!ok(x, y - 1, state[direct].fi, state[direct].se)) return false;
- y--; return true;
- };
- auto goRight = [&](int &x, int &y, int &direct) -> bool {
- if(!ok(x, y + 1, state[direct].fi, state[direct].se)) return false;
- y++; return true;
- };
- // DIRECT : 0 -> a * b
- // 1 -> b * a
- // 2 -> a * c
- // 3 -> c * a
- // 4 -> b * c
- // 5 -> c * b
- state[0] = make_pair(a, b);
- state[1] = make_pair(b, a);
- state[2] = make_pair(a, c);
- state[3] = make_pair(c, a);
- state[4] = make_pair(b, c);
- state[5] = make_pair(c, b);
- Right[0] = 2; Right[1] = 4; Right[2] = 0; Right[3] = 5; Right[4] = 1; Right[5] = 3;
- for(int i = 0; i < 6; i++) Left[i] = Right[i];
- Down[0] = 5; Down[1] = 3; Down[2] = 4; Down[3] = 1; Down[4] = 2; Down[5] = 0;
- for(int i = 0; i < 6; i++) Up[i] = Down[i];
- auto flipLeft = [&](int &x, int &y, int &direct) -> bool {
- int nDirect = Left[direct];
- if(!ok(x, y - state[nDirect].se, state[nDirect].fi, state[nDirect].se)) return false;
- direct = nDirect;
- y -= state[direct].se;
- return true;
- };
- auto flipRight = [&](int &x, int &y, int &direct) -> bool {
- int nDirect = Right[direct];
- if(!ok(x, y + state[direct].se, state[nDirect].fi, state[nDirect].se)) return false;
- y += state[direct].se;
- direct = nDirect;
- return true;
- };
- auto flipUp = [&](int &x, int &y, int &direct) -> bool {
- int nDirect = Up[direct];
- if(!ok(x - state[nDirect].fi, y, state[nDirect].fi, state[nDirect].se)) return false;
- direct = nDirect;
- x -= state[direct].fi;
- return true;
- };
- auto flipDown = [&](int &x, int &y, int &direct) -> bool {
- int nDirect = Down[direct];
- if(!ok(x + state[direct].fi, y, state[nDirect].fi, state[nDirect].se)) return false;
- x += state[direct].fi;
- direct = nDirect;
- return true;
- };
- queue<pair<pii, int>> q;
- auto addState = [&](int x, int y, int direct) -> void {
- if(visited[x][y][direct]) return;
- visited[x][y][direct] = true;
- q.push(mp(mp(x, y), direct));
- };
- q.push(mp(mp(1, 1), 0));
- visited[1][1][0] = true;
- while(!q.empty()) {
- int x = q.front().fi.fi, y = q.front().fi.se;
- int direct = q.front().se; q.pop();
- f[x][y]++;
- f[x + state[direct].fi][y + state[direct].se]++;
- f[x + state[direct].fi][y]--;
- f[x][y + state[direct].se]--;
- int u = x, v = y, curr = direct;
- if(goUp(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(goDown(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(goLeft(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(goRight(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(flipUp(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(flipDown(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(flipLeft(u, v, curr)) addState(u, v, curr);
- u = x, v = y, curr = direct;
- if(flipRight(u, v, curr)) addState(u, v, curr);
- }
- int ans = 0;
- for(int i = 1; i <= n; i++) {
- for(int j = 1; j <= m; j++) {
- f[i][j] = f[i][j] + f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
- ans += (f[i][j] > 0);
- }
- }
- cout << ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- //online
- #endif
- int tc = 1, ddd = 0;
- // cin >> tc;
- while(tc--) {
- //ddd++;
- //cout << "Case #" << ddd << ": ";
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement