제출 #1309546

#제출 시각아이디문제언어결과실행 시간메모리
1309546zadniprovskaColouring a rectangle (eJOI19_colouring)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ld long double
#define ull unsigned long long
#define pll pair<ll, ll>
#define ppll pair< pair<long long, long long>, long long >
#define ff first
#define ss second
#define pb push_back
#define pf push_front
 
const ll DIM = 500 + 7;
const ll INF = 1e9;
const ll mod = 998244353;
const ll maxlog = 20;
const ll bsize = 350;

ll a[DIM], b[DIM];
ll p[DIM][DIM];

void solve() {

    ll n, m;
    cin >> m >> n;

    for (int i=1; i<=n+m-1; i++) {
        cin >> a[i];
    }
    for (int i=1; i<=n+m-1; i++) {
        cin >> b[i];
    }

    ll mn = INF;
    for (int mask=1; mask<(1 << (2*n + 2*m - 2)); mask++) {

        for (int i=1; i<=m; i++) {
            for (int j=1; j<=n; j++) {
                p[i][j] = 0;
            }
        }
        ll cost = 0;

        ll i = 1, j = n;
        for (int bit=0; bit<(n + m - 1); bit++) {

            if (mask & (1 << bit)) {
                cost += a[bit+1];
                if (cost > mn) break;

                ll ci = i, cj = j;
                while (ci <= m && cj <= n) {
                    p[ci][cj] = 1;
                    ci++; cj++;
                }
            }

            if (j == 1) i++;
            else j--;

        }

        if (cost > mn) continue;

        i = 1; j = 1;
        for (int bit=n+m-1; bit<(2*n + 2*m - 2); bit++) {

            if (mask & (1 << bit)) {
                cost += b[bit-(n+m-1)+1];
                if (cost > mn) break;

                ll ci = i, cj = j;
                while (ci <= m && cj >= 1) {
                    p[ci][cj] = 1;
                    ci++; cj--;
                }
            }

            if (j == n) i++;
            else j++;

        }
        

        ll ok = 1;
        for (int i=1; i<=m; i++) {
            for (int j=1; j<=n; j++) {
                if (!p[i][j]) {
                    ok = 0;
                    break;
                }
            } 
            if (!ok) break;
        }

        if (ok) mn = min(mn, cost);
    }

    cout << mn << endl;



}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //freopen("atlarge.in", "r", stdin);
    //freopen("atlarge.out", "w", stdout);
 
    int ntest = 1;
    //cin >> ntest;
    while (ntest--) {
        solve();
    }
    return 0;
 
}
;
#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...