제출 #446806

#제출 시각아이디문제언어결과실행 시간메모리
446806Valaki2Colouring a rectangle (eJOI19_colouring)C++14
10 / 100
62 ms3524 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n, m; void solve_n_1() { vector<ll> a(n + m - 1, 0); vector<ll> b(n + m - 1, 0); for(ll &x : a) cin >> x; for(ll &x : b) cin >> x; reverse(b.begin(), b.end()); ll ans = 0; for(int i = 0; i < n + m - 1; ++i) ans += min(a[i], b[i]); cout << ans << "\n"; } void solve_bf_1010() { int p = n + m - 1; vector<ll> a(p, 0); vector<ll> b(p, 0); for(ll &x : a) cin >> x; for(ll &x : b) cin >> x; vector<vector<bool> > colored(1 + n, vector<bool> (1 + m, false)); vector<bool> chosen(p, false); vector<bool> paid(p, false); ll ans = INT_MAX, cur = 0; for(int mask = 0; mask < (1 << p); ++mask) { cur = 0; for(int i = 0; i < p; ++i) { if(mask & (1 << i)) { chosen[i] = true; cur += a[i]; } else { chosen[i] = false; } } for(int i = 0; i < p; ++i) { if(chosen[i]) { int diff = m - 1 - i; int y = m - i; int x = y - diff; if(y <= 0) { int z = 1 - y; x += z; y += z; } while(x <= n && y <= m) { colored[x][y] = true; ++x; ++y; } } } for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { if(!colored[i][j]) { paid[i + j - 2] = true; } } } for(int i = 0; i < p; ++i) { if(paid[i]) { cur += b[i]; } } ans = min(ans, cur); chosen.assign(p, false); paid.assign(p, false); colored.assign(1 + n, vector<bool> (1 + m, false)); } cout << ans << "\n"; } void solve() { cin >> n >> m; if(n == 1) { solve_n_1(); return; } if(n <= 20 && m <= 20) { solve_bf_1010(); return; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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...