Submission #136431

# Submission time Handle Problem Language Result Execution time Memory
136431 2019-07-25T09:50:59 Z imyujin Connect (CEOI06_connect) C++14
8 / 100
91 ms 1400 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1 << 30;

string m[30];
char p[40][30];
int dp[40][1 << 12];
int w[40][1 << 12];
vector<int> open[40];
int cnta[1 << 12];
int cntx[40];

int main() {
	int N, M;

	cin >> N >> M;
	getline(cin, m[0]);
	for(int i = 0; i < N; i++) getline(cin, m[i]);

	//for(int i = 0; i < N; i++) cout << m[i] << "\n";
	for(int i = 0; i <= M / 2; i++) {
		open[i].push_back(0);
		for(int j = 0; j < N / 2; j++) if(m[2 * j + 1][2 * i] == ' ') open[i][0] += (1 << j);
		for(int k = open[i][0]; k; k = open[i][0] & (k - 1)) open[i].push_back(open[i][0] & (k - 1));
		//cout << "open[i][0] = " << open[i][0] << "\n";
		//cout << "open[i].size = " << open[i].size() << "\n";
	}
	for(int i = 1; i <= M / 2; i++) for(int j = 0; j < N / 2; j++) if(m[2 * j + 1][2 * i - 1] == 'X') cntx[i]++;
	for(int i = 0; i < (1 << (N / 2)); i++) for(int j = 0; j < N / 2; j++) if(i & (1 << j)) cnta[i]++;
	for(int i = 0; i < M; i++) for(int j = 0; j < N / 2; j++) p[j][i] = m[i][j * 2 + 1];

	for(int i = 0; i <= M / 2; i++) for(int j = 0; j < (1 << (N / 2)); j++) dp[i][j] = INF;
	dp[0][0] = 0;
	for(int i = 1; i <= M / 2; i++) for(auto a : open[i]) for(auto b : open[i - 1]) {
		if(dp[i - 1][b] == INF) continue;
		if((cnta[a] + cnta[b] + cntx[i]) % 2) continue;
		int t = -1, s = 0;
		bool c = true;
		for(int j = 0; j < N / 2; j++) {
			if(t != -1 && p[i - 1][2 * j] == '-') {
				c = false;
				break;
			}
			if(p[i - 1][2 * j + 1] == 'X') {
				if(t == -1) t = j;
				else if((a & (1 << j)) != 0 || (b & (1 << j)) != 0) {
					c = false;
					break;
				}
				else {
					s += 2 * (j - t) + 1;
					t = -1;
				}
			}
			if((a & (1 << j)) != 0 && (b & (1 << j)) != 0) {
				if(t == -1) s += 2;
				else {
					c = false;
					break;
				}
			}
			else if(a & (1 << j)) {
				if(t == -1) {
					t = j;
					s++;
				}
				else {
					s += 2 * (j - t + 1);
					t = -1;
				}
			}
			else if(b & (1 << j)) {
				if(t == -1) t = j;
				else {
					s += 2 * (j - t) + 1;
					t = -1;
				}
			}
		}
		if(c && t == -1) {
			//if(i == 1) printf("i = %d, a = %d, b = %d, t = %d, s = %d\n", i, a, b, t, s);
			//if(dp[i - 1][b] + s < dp[i][a] && i == 6 && a == 32) printf("dp[%d][%d] = %d\n", i - 1, b, dp[i - 1][b]);
			if(dp[i - 1][b] + s < dp[i][a]) {
				dp[i][a] = dp[i - 1][b] + s;
				w[i][a] = b;
			}
		}
	}

	int cnt = 0;
	for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) if(m[i][j] == 'X') cnt++;

	cout << dp[M / 2][0] - cnt / 2 << "\n";
	vector<int> boa;
	boa.push_back(0);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Wrong score! (1073741821, expected 26)
2 Partially correct 2 ms 376 KB Partially correct (80% score). Wrong board
3 Incorrect 2 ms 376 KB Wrong score! (1073741812, expected 74)
4 Incorrect 3 ms 376 KB Wrong score! (1073741818, expected 28)
5 Partially correct 91 ms 760 KB Partially correct (80% score). Wrong board
6 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 2 ms 476 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 4 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)