답안 #1101303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101303 2024-10-16T04:07:08 Z anhphant Cell Automaton (JOI23_cell) C++14
16 / 100
257 ms 266056 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define dot cerr << "passed" << '\n';
#define debug(x) cerr << "debug : " << #x << " = " << x << '\n';

ll N, Q;
pair<ll, ll> A[100007];
struct query {
	ll t, id;
};
query Queries[500007];
ll ans[500007];

namespace subtask1 {
	ll Cnt[57], cell[2][507][507];
	const ll offset = 157;

	void solve() {
		for(int i = 1; i <= N; ++i) {
			cell[0][A[i].fi + offset][A[i].se + offset] = 1;
		}
		auto fill = [&](ll p, ll a, ll b, ll c, ll d) {
			if (cell[p][c][d] == -1) return; // grey can't fill
			if (cell[p][c][d] == 1) return; // black can't fill
			cell[(p + 1) % 2][c][d] = 1; // white near black -> fill
		};	
		// dot;
		for(int tm = 0; tm <= 500; ++tm) { // tm fix
			memset(cell[(tm + 1) % 2], 0, sizeof(cell[(tm + 1) % 2]));
			for(int i = 1; i <= 500; ++i) {
				for(int j = 1; j <= 500; ++j) {
					// 1 : black
					// -1 : grey
					// 0 : white
					if (cell[tm % 2][i][j] == 1) {
						Cnt[tm]++;
						fill(tm % 2, i, j, i - 1, j);
						fill(tm % 2, i, j, i, j - 1);
						fill(tm % 2, i, j, i + 1, j);
						fill(tm % 2, i, j, i, j + 1);
						cell[(tm + 1) % 2][i][j] = -1; // its grey now
					}
				}
			}
			// cerr << "print table " << '\n';
			// for(int i = -5 + offset; i <= 5 + offset; ++i) {
			// 	for(int j = -5 + offset; j <= 5 + offset; ++j) {
			// 		if (cell[tm % 2][i][j] == -1) cerr << 2;
			// 		else cerr << cell[tm % 2][i][j];
			// 	}
			// 	cerr << '\n';
			// }
			// cerr << '\n';
		}
		for(int i = 1; i <= Q; ++i) {
			// cerr << "query " << i << '\n';
			cout << Cnt[Queries[i].t] << '\n';
		}
	}

	void process() {
		solve();
	}
}

namespace subtask2 {
	ll dist[4007][4007];
	const ll dx[4] = {-1, 0, 0, 1};
	const ll dy[4] = {0, -1, 1, 0};
	const ll os = 2002;
	ll Cnt[1007];

	void solve() {
		for(int i = 0; i <= 4002; ++i) fill(dist[i], dist[i] + 4003, 1e18);
		queue<pair<ll, ll>> qu;
		for(int i = 1; i <= N; ++i) {
			dist[A[i].fi + os][A[i].se + os] = 0;
			qu.push({A[i].fi, A[i].se});
		}
		while(!qu.empty()) {
			auto [x, y] = qu.front();
			qu.pop();
			if (dist[x + os][y + os] == 1000) break;
			Cnt[dist[x + os][y + os]]++;
			for(int id = 0; id < 4; ++id) {
				ll x2 = x + dx[id];
				ll y2 = y + dy[id];
				if (dist[x2 + os][y2 + os] != 1e18) continue;
				dist[x2 + os][y2 + os] = dist[x + os][y + os] + 1;
				qu.push({x2, y2});
			}
		}

		for(int i = 1; i <= Q; ++i) {
			cout << Cnt[Queries[i].t] << '\n';
		}
	}

	void process() {
		solve();
	}
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0); cerr.tie(0);
	if (fopen("FILE.INP", "r")) {
		freopen("FILE.INP", "r", stdin);
		freopen("FILE.OUT", "w", stdout);
	}

	cin >> N >> Q;
	for(int i = 1; i <= N; ++i) cin >> A[i].fi >> A[i].se;
	for(int i = 1; i <= Q; ++i) {
		cin >> Queries[i].t;
		Queries[i].id = i;
	}

	subtask2 :: process();
}

Compilation message

cell.cpp: In function 'void subtask2::solve()':
cell.cpp:84:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |    auto [x, y] = qu.front();
      |         ^
cell.cpp: In function 'int main()':
cell.cpp:111:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |   freopen("FILE.INP", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cell.cpp:112:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |   freopen("FILE.OUT", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 130020 KB Output is correct
2 Correct 82 ms 130128 KB Output is correct
3 Correct 104 ms 130120 KB Output is correct
4 Correct 98 ms 130120 KB Output is correct
5 Correct 108 ms 130124 KB Output is correct
6 Correct 103 ms 130120 KB Output is correct
7 Correct 91 ms 130128 KB Output is correct
8 Correct 101 ms 130120 KB Output is correct
9 Correct 101 ms 130084 KB Output is correct
10 Correct 105 ms 130120 KB Output is correct
11 Correct 102 ms 130140 KB Output is correct
12 Correct 103 ms 130112 KB Output is correct
13 Correct 120 ms 130120 KB Output is correct
14 Correct 98 ms 130120 KB Output is correct
15 Correct 99 ms 130120 KB Output is correct
16 Correct 96 ms 130120 KB Output is correct
17 Correct 99 ms 130120 KB Output is correct
18 Correct 102 ms 130024 KB Output is correct
19 Correct 103 ms 129968 KB Output is correct
20 Correct 101 ms 130120 KB Output is correct
21 Correct 97 ms 130120 KB Output is correct
22 Correct 102 ms 130164 KB Output is correct
23 Correct 97 ms 130128 KB Output is correct
24 Correct 97 ms 130120 KB Output is correct
25 Correct 95 ms 130120 KB Output is correct
26 Correct 99 ms 130120 KB Output is correct
27 Correct 104 ms 130124 KB Output is correct
28 Correct 99 ms 130124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 130020 KB Output is correct
2 Correct 82 ms 130128 KB Output is correct
3 Correct 104 ms 130120 KB Output is correct
4 Correct 98 ms 130120 KB Output is correct
5 Correct 108 ms 130124 KB Output is correct
6 Correct 103 ms 130120 KB Output is correct
7 Correct 91 ms 130128 KB Output is correct
8 Correct 101 ms 130120 KB Output is correct
9 Correct 101 ms 130084 KB Output is correct
10 Correct 105 ms 130120 KB Output is correct
11 Correct 102 ms 130140 KB Output is correct
12 Correct 103 ms 130112 KB Output is correct
13 Correct 120 ms 130120 KB Output is correct
14 Correct 98 ms 130120 KB Output is correct
15 Correct 99 ms 130120 KB Output is correct
16 Correct 96 ms 130120 KB Output is correct
17 Correct 99 ms 130120 KB Output is correct
18 Correct 102 ms 130024 KB Output is correct
19 Correct 103 ms 129968 KB Output is correct
20 Correct 101 ms 130120 KB Output is correct
21 Correct 97 ms 130120 KB Output is correct
22 Correct 102 ms 130164 KB Output is correct
23 Correct 97 ms 130128 KB Output is correct
24 Correct 97 ms 130120 KB Output is correct
25 Correct 95 ms 130120 KB Output is correct
26 Correct 99 ms 130120 KB Output is correct
27 Correct 104 ms 130124 KB Output is correct
28 Correct 99 ms 130124 KB Output is correct
29 Correct 104 ms 130120 KB Output is correct
30 Correct 125 ms 130216 KB Output is correct
31 Correct 180 ms 130128 KB Output is correct
32 Correct 226 ms 136264 KB Output is correct
33 Correct 125 ms 130124 KB Output is correct
34 Correct 124 ms 130232 KB Output is correct
35 Correct 126 ms 130136 KB Output is correct
36 Correct 102 ms 130124 KB Output is correct
37 Correct 105 ms 129996 KB Output is correct
38 Correct 203 ms 130640 KB Output is correct
39 Correct 206 ms 132132 KB Output is correct
40 Correct 247 ms 137992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 257 ms 266056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 257 ms 266056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 233 ms 263448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 233 ms 263448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 130020 KB Output is correct
2 Correct 82 ms 130128 KB Output is correct
3 Correct 104 ms 130120 KB Output is correct
4 Correct 98 ms 130120 KB Output is correct
5 Correct 108 ms 130124 KB Output is correct
6 Correct 103 ms 130120 KB Output is correct
7 Correct 91 ms 130128 KB Output is correct
8 Correct 101 ms 130120 KB Output is correct
9 Correct 101 ms 130084 KB Output is correct
10 Correct 105 ms 130120 KB Output is correct
11 Correct 102 ms 130140 KB Output is correct
12 Correct 103 ms 130112 KB Output is correct
13 Correct 120 ms 130120 KB Output is correct
14 Correct 98 ms 130120 KB Output is correct
15 Correct 99 ms 130120 KB Output is correct
16 Correct 96 ms 130120 KB Output is correct
17 Correct 99 ms 130120 KB Output is correct
18 Correct 102 ms 130024 KB Output is correct
19 Correct 103 ms 129968 KB Output is correct
20 Correct 101 ms 130120 KB Output is correct
21 Correct 97 ms 130120 KB Output is correct
22 Correct 102 ms 130164 KB Output is correct
23 Correct 97 ms 130128 KB Output is correct
24 Correct 97 ms 130120 KB Output is correct
25 Correct 95 ms 130120 KB Output is correct
26 Correct 99 ms 130120 KB Output is correct
27 Correct 104 ms 130124 KB Output is correct
28 Correct 99 ms 130124 KB Output is correct
29 Correct 104 ms 130120 KB Output is correct
30 Correct 125 ms 130216 KB Output is correct
31 Correct 180 ms 130128 KB Output is correct
32 Correct 226 ms 136264 KB Output is correct
33 Correct 125 ms 130124 KB Output is correct
34 Correct 124 ms 130232 KB Output is correct
35 Correct 126 ms 130136 KB Output is correct
36 Correct 102 ms 130124 KB Output is correct
37 Correct 105 ms 129996 KB Output is correct
38 Correct 203 ms 130640 KB Output is correct
39 Correct 206 ms 132132 KB Output is correct
40 Correct 247 ms 137992 KB Output is correct
41 Runtime error 257 ms 266056 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -