Submission #1106919

#TimeUsernameProblemLanguageResultExecution timeMemory
1106919duckindogFlooding Wall (BOI24_wall)C++17
8 / 100
192 ms2640 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 500'000 + 10,
          M = 1'000'000'007;
int n;
int a[N], b[N];

void add(auto& x, const auto& y) { 
  x += y;
  if (x >= M) x -= M;
}

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

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

  long long answer = 0;
  for (int mask = 0; mask < (1 << n); ++mask) { 
    vector<int> fwd(n + 2), bwd(n + 2);
    for (int i = 1; i <= n; ++i)
      fwd[i] = max(fwd[i - 1], (mask >> (i - 1) & 1) ? a[i] : b[i]);
    for (int i = n; i >= 1; --i) 
      bwd[i] = max(bwd[i + 1], (mask >> (i - 1) & 1) ? a[i] : b[i]);
    
    for (int i = 1; i <= n; ++i) { 
      int height = ((mask >> (i - 1) & 1) ? a[i] : b[i]);
      int mi = min(fwd[i - 1], bwd[i + 1]);
      if (mi > height) add(answer, mi - height);
    }
  }

  cout << answer << "\n";
}

Compilation message (stderr)

Main.cpp:10:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   10 | void add(auto& x, const auto& y) {
      |          ^~~~
Main.cpp:10:25: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   10 | void add(auto& x, const auto& y) {
      |                         ^~~~
#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...