Submission #945595

# Submission time Handle Problem Language Result Execution time Memory
945595 2024-03-14T05:26:40 Z itslq Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
23 ms 1228 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int md(int x) {
    if (x < 0) return (x % MOD) + MOD;
    if (x < MOD) return x;
    return x % MOD;
}

signed main() {
    int N, minH, ans = 0;
    bool st3, st4, st5, S;
    cin >> N;
    vector<int> H(N), W(N);

    for (int i = 0; i < N; i++) {
        cin >> H[i];
        if (H[i] > 2) st3 = 0;
        if (H[i] != H[0]) st4 = 0;
        if (i && H[i] < H[i - 1]) st5 = 0;
    }
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        S += W[i];
    }

    if (st3) {
        vector<int> compH{H[0]}, compW{W[0]};
        for (int i = 1; i < N; i++) {
            if (H[i] == compH.back()) compW.back() += W[i];
            else {
                compH.push_back(H[i]);
                compW.push_back(W[i]);
            }
        }
        ans = md(S * (S + 1) / 2);

        for (int i = 0; i < compH.size(); i++) {
            if (H[i] == 2) {
                ans = md(ans + W[i] * (W[i] + 1) / 2);
            }
        }

        cout << ans;
        return 0;
    }

    if (N <= 1000) {
        for (int i = 0; i < N; i++) {
            minH = H[i];
            ans = md(ans + md(H[i] * (H[i] + 1) / 2) * md(W[i] * (W[i] + 1) / 2));
            for (int j = i + 1; j < N; j++) {
                minH = min(minH, H[j]);
                ans = md(ans + md(W[i] * W[j]) * md(minH * (minH + 1) / 2));
            }
        }

        cout << ans;
    }
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:42:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 0; i < compH.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
fancyfence.cpp:16:15: warning: variable 'st4' set but not used [-Wunused-but-set-variable]
   16 |     bool st3, st4, st5, S;
      |               ^~~
fancyfence.cpp:16:20: warning: variable 'st5' set but not used [-Wunused-but-set-variable]
   16 |     bool st3, st4, st5, S;
      |                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Incorrect 23 ms 1224 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Incorrect 5 ms 584 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Incorrect 6 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 4 ms 544 KB Output is correct
11 Incorrect 19 ms 1228 KB Output isn't correct
12 Halted 0 ms 0 KB -