Submission #643583

# Submission time Handle Problem Language Result Execution time Memory
643583 2022-09-22T14:35:58 Z ghostwriter Vision Program (IOI19_vision) C++14
12 / 100
32 ms 5832 KB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    VOI23 gold medal
*/
namespace subtask1235 {
	void construct_network(int H, int W, int K) {
		vi ans;
		FOR(i, 0, H - 1)
		FOR(j, 0, W - 1) {
			vi tmp;
			FOR(x, i, H - 1)
			FOR(y, 0, W - 1) {
				if (x == i && y <= j) continue;
				if (abs(i - x) + abs(j - y) != K) continue;
				int index = x * W + y;
				tmp.pb(index);
			}
			if (tmp.empty()) continue;
			int pos = add_or({tmp});
			pos = add_and({i * W + j, pos});
			ans.pb(pos);
		}
		add_or(ans);
	}
}
namespace solution {
	const int N = 805;
	const int D = 400;
	int c[N][N], d1[N], d2[N];
	void construct_network(int H, int W, int K) {
		FOR(i, 0, H - 1)
		FOR(j, 0, W - 1) {
			if (c[i][j]) continue;
			vi tmp;
			int x = i, y = j;
			WHILE(x >= 0 && y >= 0) {
				tmp.pb(x * W + y);
				c[x][y] = 1;
				--x;
				--y;
			}
			x = i;
			y = j;
			++x;
			++y;
			WHILE(x < H && y < W) {
				tmp.pb(x * W + y);
				c[x][y] = 1;
				++x;
				++y;
			}
			d1[i - j + D] = add_or(tmp);
		}
		memset(c, 0, sizeof c);
		FOR(i, 0, H - 1)
		FOR(j, 0, W - 1) {
			if (c[i][j]) continue;
			vi tmp;
			int x = i, y = j;
			WHILE(x >= 0 && j < W) {
				tmp.pb(x * W + y);
				c[x][y] = 1;
				--x;
				++y;
			}
			++x;
			--y;
			WHILE(x < H && y >= 0) {
				tmp.pb(x * W + y);
				c[x][y] = 1;
				++x;
				--y;
			}
			d2[i + j + D] = add_or(tmp);
		}
		vi tmp;
		FOR(i, 0, N - 1) {
			if (!d1[i]) continue;
			int x = i - D, pos1 = d1[i];
			FOR(j, 0, i - 1) {
				if (!d1[j]) continue;
				int y = j - D, pos2 = d1[j];
				if (abs(x - y) != K) continue;
				tmp.pb(add_and({pos1, pos2}));
			}
		}
		FOR(i, 0, N - 1) {
			if (!d2[i]) continue;
			int x = i - D, pos1 = d2[i];
			FOR(j, 0, i - 1) {
				if (!d2[j]) continue;
				int y = j - D, pos2 = d2[j];
				if (abs(x - y) != K) continue;
				tmp.pb(add_and({pos1, pos2}));
			}
		}
		int posk = add_or(tmp);
		if (K == W + H - 2) {
			add_and({posk});
			return;
		}
		tmp.clear();
		FOR(i, 0, N - 1) {
			if (!d1[i]) continue;
			int x = i - D, pos1 = d1[i];
			vi tmp1;
			FOR(j, 0, i - 1) {
				if (!d1[j]) continue;
				int y = j - D, pos2 = d1[j];
				if (abs(x - y) <= K) continue;
				tmp1.pb(pos2);
			}
			if (tmp1.empty()) continue;
			int pos3 = add_or(tmp1);
			tmp.pb(add_and({pos1, pos3}));
		}
		FOR(i, 0, N - 1) {
			if (!d2[i]) continue;
			int x = i - D, pos1 = d2[i];
			vi tmp1;
			FOR(j, 0, i - 1) {
				if (!d2[j]) continue;
				int y = j - D, pos2 = d2[j];
				if (abs(x - y) <= K) continue;
				tmp1.pb(pos2);
			}
			if (tmp1.empty()) continue;
			int pos3 = add_or(tmp1);
			tmp.pb(add_and({pos1, pos3}));
		}
		int posgk = add_or(tmp);
		posgk = add_not(posgk);
		add_and({posk, posgk});
	}
}
void construct_network(int H, int W, int K) {
	// if (max(H, W) <= 30 || min(H, W) == 1) {
	// 	subtask1235::construct_network(H, W, K);
	// 	return;
	// }
	solution::construct_network(H, W, K);
}
/*
2 3 2
0 0 1 0
-1
*/
/*
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

vision.cpp: In function 'void subtask1235::construct_network(int, int, int)':
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:46:3: note: in expansion of macro 'FOR'
   46 |   FOR(i, 0, H - 1)
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:47:3: note: in expansion of macro 'FOR'
   47 |   FOR(j, 0, W - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:49:4: note: in expansion of macro 'FOR'
   49 |    FOR(x, i, H - 1)
      |    ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'y' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:50:4: note: in expansion of macro 'FOR'
   50 |    FOR(y, 0, W - 1) {
      |    ^~~
vision.cpp: In function 'void solution::construct_network(int, int, int)':
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:69:3: note: in expansion of macro 'FOR'
   69 |   FOR(i, 0, H - 1)
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:70:3: note: in expansion of macro 'FOR'
   70 |   FOR(j, 0, W - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:93:3: note: in expansion of macro 'FOR'
   93 |   FOR(i, 0, H - 1)
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:94:3: note: in expansion of macro 'FOR'
   94 |   FOR(j, 0, W - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:115:3: note: in expansion of macro 'FOR'
  115 |   FOR(i, 0, N - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:118:4: note: in expansion of macro 'FOR'
  118 |    FOR(j, 0, i - 1) {
      |    ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:125:3: note: in expansion of macro 'FOR'
  125 |   FOR(i, 0, N - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:128:4: note: in expansion of macro 'FOR'
  128 |    FOR(j, 0, i - 1) {
      |    ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:141:3: note: in expansion of macro 'FOR'
  141 |   FOR(i, 0, N - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:145:4: note: in expansion of macro 'FOR'
  145 |    FOR(j, 0, i - 1) {
      |    ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:155:3: note: in expansion of macro 'FOR'
  155 |   FOR(i, 0, N - 1) {
      |   ^~~
vision.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
vision.cpp:159:4: note: in expansion of macro 'FOR'
  159 |    FOR(j, 0, i - 1) {
      |    ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 1 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Incorrect 2 ms 2764 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 1 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Incorrect 2 ms 2764 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 1 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Incorrect 2 ms 2764 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 1 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Incorrect 2 ms 2764 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3284 KB Output is correct
2 Correct 3 ms 2900 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 13 ms 3548 KB Output is correct
6 Correct 7 ms 3408 KB Output is correct
7 Correct 6 ms 3284 KB Output is correct
8 Correct 5 ms 3156 KB Output is correct
9 Correct 6 ms 3284 KB Output is correct
10 Correct 4 ms 3028 KB Output is correct
11 Correct 3 ms 2900 KB Output is correct
12 Correct 3 ms 2900 KB Output is correct
13 Correct 2 ms 2904 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 9 ms 3592 KB Output is correct
16 Correct 7 ms 3412 KB Output is correct
17 Correct 8 ms 3228 KB Output is correct
18 Correct 7 ms 3284 KB Output is correct
19 Correct 6 ms 3284 KB Output is correct
20 Correct 6 ms 3156 KB Output is correct
21 Correct 1 ms 2772 KB Output is correct
22 Correct 1 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2772 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 5832 KB Output is correct
2 Incorrect 2 ms 2772 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 1 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Incorrect 2 ms 2764 KB on inputs (0, 0), (1, 0), expected 1, but computed 0
6 Halted 0 ms 0 KB -