Submission #788094

#TimeUsernameProblemLanguageResultExecution timeMemory
788094Chal1shkanColouring a rectangle (eJOI19_colouring)C++14
20 / 100
2075 ms6536 KiB
//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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...