Submission #650251

# Submission time Handle Problem Language Result Execution time Memory
650251 2022-10-13T08:43:22 Z alvinpiter Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
3 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 100000

int n;
LL h[MAXN + 3], w[MAXN + 3], sumWidth[MAXN + 3], sumFhw = 0, ans = 0;
stack<int> st;

LL f(LL k) {
  LL k1 = k + 1;
  return k%2 == 0 ? ((k/2)%MOD * (k1)%MOD)%MOD : (k%MOD * (k1/2)%MOD)%MOD;
}

int solveBruteForce() {
  int psum[55][55];
  memset(psum, 0, sizeof(psum));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= h[i]; j++) {
      psum[i][j] = 1;
    }
    cout << endl;
  }

  for (int i = 1; i <= 50; i++) {
    for (int j = 1; j <= 50; j++) {
      psum[i][j] += psum[i - 1][j] + psum[i][j - 1] - psum[i - 1][j - 1];
    }
  }

  int ans = 0;
  for (int i1 = 1; i1 <= 50; i1++) {
    for (int j1 = 1; j1 <= 50; j1++) {
      for (int i2 = i1; i2 <= 50; i2++) {
        for (int j2 = j1; j2 <= 50; j2++) {
          int sum = psum[i2][j2] - psum[i2][j1 - 1] - psum[i1 - 1][j2] + psum[i1 - 1][j1 - 1];
          if (sum == (i2 - i1 + 1) * (j2 - j1 + 1)) {
            ans += 1;
          }
        }
      }
    }
  }

  return ans;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }

  sumWidth[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
    sumWidth[i] = sumWidth[i - 1] + w[i];
  }

  cout << solveBruteForce() << endl;
  return 0;

  for (int i = 1; i <= n; i++) {
    LL rectanglesOnTheCurrentFence = (f(h[i]) * f(w[i]))%MOD;
    ans = (ans + rectanglesOnTheCurrentFence)%MOD;

    while (!st.empty() && h[st.top()] >= h[i]) {
      LL fhw = (f(h[st.top()]) * w[st.top()])%MOD;
      sumFhw = (sumFhw - fhw + MOD)%MOD;

      st.pop();
    }

    int firstLowerIdx = (st.empty() ? 0 : st.top());

    LL rectanglesOnTheCurrentFenceAndTallerNeighbors = 0;
    if (firstLowerIdx != i - 1) {
      rectanglesOnTheCurrentFenceAndTallerNeighbors = (((sumWidth[i - 1] - sumWidth[firstLowerIdx])%MOD * w[i])%MOD * f(h[i]))%MOD;
      ans = (ans + rectanglesOnTheCurrentFenceAndTallerNeighbors)%MOD;
    }

    LL rectanglesOnTheCurrentFenceAndLowerNeighbors = (sumFhw * w[i])%MOD;
    ans = (ans + rectanglesOnTheCurrentFenceAndLowerNeighbors)%MOD;

    st.push(i);
    sumFhw = (sumFhw + (f(h[i]) * w[i])%MOD)%MOD;
  }

  cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -