Submission #110566

# Submission time Handle Problem Language Result Execution time Memory
110566 2019-05-11T07:52:40 Z ckodser Wall (CEOI14_wall) C++14
0 / 100
2000 ms 24436 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];
ll dp[N][N][1 << K];
priority_queue < tuple < int , int , int , int > > Pq;
inline void Relax(int a, int b, int mask, int d)
{
	if (dp[a][b][mask] > d)
	{
		dp[a][b][mask] = d;
		Pq.push(make_tuple(d, a, b, mask));
	}
}
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]);
	assert((int)vec.size() <= 10);
	memset(dp, 63, sizeof(dp)); dp[0][0][0] = 0;
	Pq.push({0, 0, 0, 0});
	while (Pq.size())
	{
		int d, a, b, mask;
		tie(d, a, b, mask) = Pq.top();
		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)
		{
			int _mask = mask;
			for (int i = 0; i < (int)vec.size(); i++)
				if (vec[i].first >= a && vec[i].second == b - 1)
					_mask ^= (1 << i);
			Relax(a, b - 1, _mask, d + horz[a][b - 1]);
		}

		// Right :
		if (b < m)
		{
			int _mask = mask;
			for (int i = 0; i < (int)vec.size(); i++)
				if (vec[i].first >= a && vec[i].second == b)
					_mask ^= (1 << i);
			Relax(a, b + 1, _mask, 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]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 239 ms 15872 KB Output is correct
2 Execution timed out 2048 ms 16000 KB Time limit exceeded
3 Execution timed out 2047 ms 15872 KB Time limit exceeded
4 Execution timed out 2048 ms 15872 KB Time limit exceeded
5 Execution timed out 2055 ms 15872 KB Time limit exceeded
6 Execution timed out 2029 ms 15872 KB Time limit exceeded
7 Execution timed out 2047 ms 20380 KB Time limit exceeded
8 Execution timed out 2061 ms 16296 KB Time limit exceeded
9 Execution timed out 2047 ms 15872 KB Time limit exceeded
10 Execution timed out 2058 ms 15872 KB Time limit exceeded
11 Execution timed out 2047 ms 20236 KB Time limit exceeded
12 Execution timed out 2064 ms 16520 KB Time limit exceeded
13 Execution timed out 2013 ms 16420 KB Time limit exceeded
14 Execution timed out 2037 ms 20224 KB Time limit exceeded
15 Execution timed out 2058 ms 15872 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Execution timed out 2080 ms 15972 KB Time limit exceeded
5 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 4 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Execution timed out 2036 ms 18028 KB Time limit exceeded
10 Execution timed out 2028 ms 16252 KB Time limit exceeded
11 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Execution timed out 2063 ms 24436 KB Time limit exceeded
15 Execution timed out 2033 ms 16600 KB Time limit exceeded
16 Execution timed out 2031 ms 15992 KB Time limit exceeded
17 Runtime error 8 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Execution timed out 8 ms 768 KB Time limit exceeded (wall clock)
2 Execution timed out 8 ms 640 KB Time limit exceeded (wall clock)
3 Execution timed out 9 ms 672 KB Time limit exceeded (wall clock)
4 Execution timed out 7 ms 640 KB Time limit exceeded (wall clock)
5 Execution timed out 12 ms 1152 KB Time limit exceeded (wall clock)
6 Execution timed out 7 ms 768 KB Time limit exceeded (wall clock)
7 Runtime error 11 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 11 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Execution timed out 11 ms 868 KB Time limit exceeded (wall clock)
10 Execution timed out 19 ms 768 KB Time limit exceeded (wall clock)
11 Execution timed out 10 ms 768 KB Time limit exceeded (wall clock)
12 Execution timed out 8 ms 768 KB Time limit exceeded (wall clock)
13 Execution timed out 11 ms 896 KB Time limit exceeded (wall clock)
14 Execution timed out 25 ms 1272 KB Time limit exceeded (wall clock)
15 Runtime error 33 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Execution timed out 20 ms 1152 KB Time limit exceeded (wall clock)
17 Execution timed out 22 ms 888 KB Time limit exceeded (wall clock)
18 Execution timed out 29 ms 888 KB Time limit exceeded (wall clock)
19 Execution timed out 17 ms 1024 KB Time limit exceeded (wall clock)
20 Execution timed out 35 ms 1016 KB Time limit exceeded (wall clock)