Submission #788094

# Submission time Handle Problem Language Result Execution time Memory
788094 2023-07-19T18:20:58 Z Chal1shkan Colouring a rectangle (eJOI19_colouring) C++14
20 / 100
2000 ms 6536 KB
//Bismillahir-Rahmanir-Rahim

# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
# define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 5e5 + 7;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m;
int a[maxn];
int b[maxn];
bool used[555][555];
bool was[555];

void ma1n (/* SABR */)
{
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n + m - 1; ++i)
	{
		cin >> b[i];
	}
	int sz = n + m - 1;
	ll ans = inf;
	for (int mask = 0; mask < (1LL << sz); ++mask)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
			{
				used[i][j] = 0;
			}
		}
		for (int i = 0; i < n + m - 1; ++i)
		{
			was[i] = 0;
		}
		ll cur = 0;
		for (int i = 0; i < sz; ++i)
		{
			if (mask & (1LL << i))
			{
				cur += b[i];
				for (int j = 0; j < n; ++j)
				{
					if (i - j >= 0 &&  i - j < m)	
					{
						used[j][i - j] = 1;
					}
				}	
			}
		}
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
			{
				if (!used[i][j])
				{
					//st.insert(i - j + m - 1);
					was[i - j + m - 1] = 1;
				}
			}
		}
		for (int i = 0; i < sz; ++i)
		{
			if (was[i]) cur += a[i];
		}
		ans = min(ans, cur);
//		cout << mask << ' ' << cur << nl;
	}
	cout << ans << nl;
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//    cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}

// 998batrr | BbIWEJI 3A TObOU!!!
// tourist  | BbIWEJI 3A TObOU!!!
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 255 ms 340 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 266 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 251 ms 340 KB Output is correct
19 Correct 116 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 255 ms 340 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 266 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 251 ms 340 KB Output is correct
19 Correct 116 ms 340 KB Output is correct
20 Execution timed out 2075 ms 336 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 255 ms 340 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 266 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 251 ms 340 KB Output is correct
19 Correct 116 ms 340 KB Output is correct
20 Execution timed out 2075 ms 336 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 6536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 255 ms 340 KB Output is correct
12 Correct 6 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 266 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 251 ms 340 KB Output is correct
19 Correct 116 ms 340 KB Output is correct
20 Execution timed out 2075 ms 336 KB Time limit exceeded
21 Halted 0 ms 0 KB -