Submission #1051400

#TimeUsernameProblemLanguageResultExecution timeMemory
1051400NeroZeinFlooding Wall (BOI24_wall)C++17
8 / 100
369 ms600 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif const int md = (int) 1e9 + 7; void add(int& x, int y) { x += y; if (x >= md) { x -= md; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> b(n); for (int i = 0; i < n; ++i) { cin >> b[i]; } int water = 0; for (int mask = 0; mask < (1 << n); ++mask) { vector<int> c(n); for (int i = 0; i < n; ++i) { c[i] = (mask >> i & 1 ? b[i] : a[i]); } vector<bool> mark(n); for (int i = 0, mx = 0; i < n; ++i) { if (c[i] > mx) { mark[i] = true; mx = c[i]; } } for (int i = n - 1, mx = 0; i >= 0; --i) { if (c[i] > mx) { mark[i] = true; mx = c[i]; } } vector<int> d(n); for (int i = 0; i < n; ++i) { for (int j = i; j >= 0; --j) { if (mark[j]) { d[i] = c[j]; break; } } for (int j = i; j < n; ++j) { if (mark[j]) { d[i] = min(d[i], c[j]); break; } } add(water, d[i] - c[i]); } } cout << water << '\n'; 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...