답안 #643578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643578 2022-09-22T14:25:15 Z ghostwriter Vision Program (IOI19_vision) C++14
44 / 100
4 ms 980 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 && j >= 0) {
				tmp.pb(x * W + y);
				c[x][y] = 1;
				--x;
				--y;
			}
			++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}));
			}
		}
		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];
			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}));
			}
		}
		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 3
0 0 1 2
-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:91:3: note: in expansion of macro 'FOR'
   91 |   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:92:3: note: in expansion of macro 'FOR'
   92 |   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:113:3: note: in expansion of macro 'FOR'
  113 |   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:116:4: note: in expansion of macro 'FOR'
  116 |    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:129:3: note: in expansion of macro 'FOR'
  129 |   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:132:4: note: in expansion of macro 'FOR'
  132 |    FOR(j, 0, i - 1) {
      |    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Incorrect 1 ms 596 KB WA in grader: Invalid index
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 244 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB WA in grader: Invalid index
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 980 KB WA in grader: Invalid index
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 220 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Incorrect 1 ms 596 KB WA in grader: Invalid index
39 Halted 0 ms 0 KB -