답안 #1101301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101301 2024-10-16T04:05:43 Z anhphant Cell Automaton (JOI23_cell) C++14
4 / 100
157 ms 153276 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[3007][3007];
	const ll dx[4] = {-1, 0, 0, 1};
	const ll dy[4] = {0, -1, 1, 0};
	const ll os = 1002;
	ll Cnt[1007];

	void solve() {
		for(int i = 0; i <= 3002; ++i) fill(dist[i], dist[i] + 3003, 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 60 ms 73244 KB Output is correct
2 Correct 62 ms 73080 KB Output is correct
3 Correct 66 ms 73288 KB Output is correct
4 Correct 64 ms 73040 KB Output is correct
5 Correct 62 ms 73040 KB Output is correct
6 Correct 63 ms 73040 KB Output is correct
7 Correct 65 ms 73040 KB Output is correct
8 Correct 63 ms 73544 KB Output is correct
9 Correct 65 ms 73040 KB Output is correct
10 Correct 63 ms 73040 KB Output is correct
11 Correct 62 ms 73040 KB Output is correct
12 Correct 71 ms 73288 KB Output is correct
13 Correct 75 ms 73288 KB Output is correct
14 Correct 67 ms 73296 KB Output is correct
15 Correct 70 ms 73296 KB Output is correct
16 Correct 62 ms 73036 KB Output is correct
17 Correct 65 ms 73052 KB Output is correct
18 Correct 61 ms 73252 KB Output is correct
19 Correct 59 ms 73044 KB Output is correct
20 Correct 59 ms 73052 KB Output is correct
21 Correct 59 ms 73032 KB Output is correct
22 Correct 58 ms 73264 KB Output is correct
23 Correct 63 ms 73040 KB Output is correct
24 Correct 59 ms 73096 KB Output is correct
25 Correct 59 ms 74568 KB Output is correct
26 Correct 65 ms 73032 KB Output is correct
27 Correct 62 ms 73296 KB Output is correct
28 Correct 61 ms 73052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 73244 KB Output is correct
2 Correct 62 ms 73080 KB Output is correct
3 Correct 66 ms 73288 KB Output is correct
4 Correct 64 ms 73040 KB Output is correct
5 Correct 62 ms 73040 KB Output is correct
6 Correct 63 ms 73040 KB Output is correct
7 Correct 65 ms 73040 KB Output is correct
8 Correct 63 ms 73544 KB Output is correct
9 Correct 65 ms 73040 KB Output is correct
10 Correct 63 ms 73040 KB Output is correct
11 Correct 62 ms 73040 KB Output is correct
12 Correct 71 ms 73288 KB Output is correct
13 Correct 75 ms 73288 KB Output is correct
14 Correct 67 ms 73296 KB Output is correct
15 Correct 70 ms 73296 KB Output is correct
16 Correct 62 ms 73036 KB Output is correct
17 Correct 65 ms 73052 KB Output is correct
18 Correct 61 ms 73252 KB Output is correct
19 Correct 59 ms 73044 KB Output is correct
20 Correct 59 ms 73052 KB Output is correct
21 Correct 59 ms 73032 KB Output is correct
22 Correct 58 ms 73264 KB Output is correct
23 Correct 63 ms 73040 KB Output is correct
24 Correct 59 ms 73096 KB Output is correct
25 Correct 59 ms 74568 KB Output is correct
26 Correct 65 ms 73032 KB Output is correct
27 Correct 62 ms 73296 KB Output is correct
28 Correct 61 ms 73052 KB Output is correct
29 Correct 65 ms 73288 KB Output is correct
30 Correct 91 ms 73312 KB Output is correct
31 Correct 121 ms 73300 KB Output is correct
32 Incorrect 157 ms 80600 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 140 ms 153276 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 140 ms 153276 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 125 ms 148180 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 125 ms 148180 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 73244 KB Output is correct
2 Correct 62 ms 73080 KB Output is correct
3 Correct 66 ms 73288 KB Output is correct
4 Correct 64 ms 73040 KB Output is correct
5 Correct 62 ms 73040 KB Output is correct
6 Correct 63 ms 73040 KB Output is correct
7 Correct 65 ms 73040 KB Output is correct
8 Correct 63 ms 73544 KB Output is correct
9 Correct 65 ms 73040 KB Output is correct
10 Correct 63 ms 73040 KB Output is correct
11 Correct 62 ms 73040 KB Output is correct
12 Correct 71 ms 73288 KB Output is correct
13 Correct 75 ms 73288 KB Output is correct
14 Correct 67 ms 73296 KB Output is correct
15 Correct 70 ms 73296 KB Output is correct
16 Correct 62 ms 73036 KB Output is correct
17 Correct 65 ms 73052 KB Output is correct
18 Correct 61 ms 73252 KB Output is correct
19 Correct 59 ms 73044 KB Output is correct
20 Correct 59 ms 73052 KB Output is correct
21 Correct 59 ms 73032 KB Output is correct
22 Correct 58 ms 73264 KB Output is correct
23 Correct 63 ms 73040 KB Output is correct
24 Correct 59 ms 73096 KB Output is correct
25 Correct 59 ms 74568 KB Output is correct
26 Correct 65 ms 73032 KB Output is correct
27 Correct 62 ms 73296 KB Output is correct
28 Correct 61 ms 73052 KB Output is correct
29 Correct 65 ms 73288 KB Output is correct
30 Correct 91 ms 73312 KB Output is correct
31 Correct 121 ms 73300 KB Output is correct
32 Incorrect 157 ms 80600 KB Output isn't correct
33 Halted 0 ms 0 KB -