Submission #854905

# Submission time Handle Problem Language Result Execution time Memory
854905 2023-09-29T10:01:42 Z anhphant Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
3 ms 2648 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N, H[500007], W[500007];
const ll mod = 1e9 + 7;

void initialize() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen("FILE.INP", "r")) {
        freopen("FILE.INP", "r", stdin);
        freopen("FILE.OUT", "w", stdout);
    }
    cin >> N;
    for(int i = 1; i <= N; ++i) cin >> H[i];
    for(int i = 1; i <= N; ++i) cin >> W[i];
}

namespace subtask2 {
    ll A[57][57];

    void solve() {
        for(int i = 1; i <= N; ++i) {
            for(int j = 1; j <= H[i]; ++j) {
                A[i][j] = 1;
            }
        }

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

        ll ans = 0;

        for(int i = 1; i <= 50; ++i) {
            for(int j = 1; j <= 50; ++j) {
                for(int k = i; k <= 50; ++k) {
                    for(int l = j; l <= 50; ++l) {
                        ans += (A[k][l] - A[i - 1][l] - A[k][j - 1] + A[i - 1][j - 1])
                                == ((k - i + 1) * (l - j + 1));
                    }
                }
            }
        }

        cout << ans;
    }

    void process() {
        solve();
    }
}

namespace subtask3 {
    void solve() {
        ll ans = 0;
        vector<ll> segment;
        for(int i = 1, sdw = 0; i <= N + 1; ++i) {
            if (i == N + 1 || H[i] == 1) {
                segment.push_back(sdw);
                sdw = 0;
            }
            else {
                sdw += W[i];
            }
        }

        for(ll c : segment) {
            ll x1 = c;
            ll x2 = c + 1;
            if (x1 % 2 == 0) x1 /= 2;
            else x2 /= 2;
            x1 %= mod;
            x2 %= mod;
            ll k = (x1 * x2) % mod;
            ans += (k * 2) % mod;
            ans %= mod;
        }

        ll k = 0;
        k = accumulate(W + 1, W + 1 + N, 0LL);
        ll x1 = k;
        ll x2 = k + 1;
        if (x1 % 2 == 0) x1 /= 2;
        else x2 /= 2;
        x1 %= mod;
        x2 %= mod;
        k = (x1 * x2) % mod;

        cout << (ans + k) % mod;
    }

    void process() {
        solve();
    }
}

int main() {
    initialize();
    if (N <= 50 && *max_element(H + 1, H + 1 + N) <= 50 && *max_element(W + 1, W + 1 + N) == 1)
        subtask2 :: solve();
    else subtask3 :: solve();
}

Compilation message

fancyfence.cpp: In function 'void initialize()':
fancyfence.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen("FILE.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen("FILE.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2396 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 3 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -