답안 #112514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112514 2019-05-20T11:29:51 Z Kastanda Wall (CEOI14_wall) C++11
30 / 100
863 ms 20196 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 44, K = 10;
int n, m, vert[N][N], horz[N][N], F[N][N];
ll dp[N][N][1 << K];
priority_queue < pair < ll , int > > Pq;
inline void Relax(int a, int b, int mask, ll d)
{
	if (dp[a][b][mask] > d)
	{
		dp[a][b][mask] = d;
		Pq.push(make_pair(- d, (mask << 12) | (b << 6) | a));
	}
}
int main()
{
	scanf("%d%d", &n, &m);
	vector < pair < int , int > > vec;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			int b;
			scanf("%d", &b);
			if (b)
				vec.push_back({i, j});
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= m; j++)
			scanf("%d", &vert[i][j]);
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < m; j++)
			scanf("%d", &horz[i][j]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			for (int h = 0; h < (int)vec.size(); h++)
				if (vec[h].first >= i && vec[h].second == j)
					F[i][j] ^= 1 << h;
		}
	assert((int)vec.size() <= 10);
	memset(dp, 63, sizeof(dp)); dp[0][0][0] = 0;
	Pq.push({0, 0});
	while (Pq.size())
	{
		int d, a, b, mask, tmp;
	   	d = - Pq.top().first;
		tmp = Pq.top().second;
		a = tmp & 63; tmp >>= 6;
		b = tmp & 63; tmp >>= 6;
		mask = tmp;
		Pq.pop();
		if (d > dp[a][b][mask])
			continue;

		// Up :
		if (a > 0)
			Relax(a - 1, b, mask, d + vert[a - 1][b]);

		// Down :
		if (a < n)
			Relax(a + 1, b, mask, d + vert[a][b]);

		// Left :
		if (b > 0)
			Relax(a, b - 1, mask ^ F[a][b - 1], d + horz[a][b - 1]);

		// Right :
		if (b < m)
			Relax(a, b + 1, mask ^ F[a][b], d + horz[a][b]);
	}
	return !printf("%lld\n", dp[0][0][(1 << (int)vec.size()) - 1]);
}

Compilation message

wall.cpp: In function 'int main()':
wall.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
wall.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &b);
    ~~~~~^~~~~~~~~~
wall.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &vert[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
wall.cpp:33:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &horz[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15872 KB Output is correct
2 Correct 15 ms 15872 KB Output is correct
3 Correct 14 ms 15872 KB Output is correct
4 Correct 18 ms 15872 KB Output is correct
5 Correct 14 ms 15872 KB Output is correct
6 Correct 16 ms 15872 KB Output is correct
7 Correct 434 ms 18000 KB Output is correct
8 Correct 21 ms 16256 KB Output is correct
9 Correct 15 ms 15872 KB Output is correct
10 Correct 16 ms 15872 KB Output is correct
11 Correct 757 ms 20096 KB Output is correct
12 Correct 39 ms 16000 KB Output is correct
13 Correct 204 ms 18028 KB Output is correct
14 Correct 863 ms 20196 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Correct 16 ms 16000 KB Output is correct
5 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Correct 100 ms 17008 KB Output is correct
10 Correct 22 ms 16256 KB Output is correct
11 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Correct 828 ms 17108 KB Output is correct
15 Correct 109 ms 18032 KB Output is correct
16 Correct 20 ms 16000 KB Output is correct
17 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 1 ms 528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 7 ms 768 KB Time limit exceeded (wall clock)
2 Execution timed out 6 ms 640 KB Time limit exceeded (wall clock)
3 Execution timed out 7 ms 640 KB Time limit exceeded (wall clock)
4 Execution timed out 4 ms 640 KB Time limit exceeded (wall clock)
5 Execution timed out 11 ms 1144 KB Time limit exceeded (wall clock)
6 Execution timed out 6 ms 768 KB Time limit exceeded (wall clock)
7 Runtime error 11 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 10 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Execution timed out 10 ms 896 KB Time limit exceeded (wall clock)
10 Execution timed out 10 ms 896 KB Time limit exceeded (wall clock)
11 Execution timed out 9 ms 768 KB Time limit exceeded (wall clock)
12 Execution timed out 7 ms 768 KB Time limit exceeded (wall clock)
13 Execution timed out 10 ms 896 KB Time limit exceeded (wall clock)
14 Execution timed out 23 ms 1272 KB Time limit exceeded (wall clock)
15 Runtime error 18 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Execution timed out 16 ms 1024 KB Time limit exceeded (wall clock)
17 Execution timed out 15 ms 1124 KB Time limit exceeded (wall clock)
18 Execution timed out 16 ms 1024 KB Time limit exceeded (wall clock)
19 Execution timed out 15 ms 1024 KB Time limit exceeded (wall clock)
20 Execution timed out 15 ms 1016 KB Time limit exceeded (wall clock)