Submission #882843

# Submission time Handle Problem Language Result Execution time Memory
882843 2023-12-03T20:44:44 Z hamidh100 Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
1000 ms 1736 KB
/* In the name of God */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"

const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;

inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); }
inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); }
inline int _mlt(ll a, ll b){ return (a * b % MOD); }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }

const int MAXN = 2e5 + 5, inv2 = (MOD + 1) / 2;

int C(int x){ return _mlt(_mlt(x, x - 1), inv2); }

int h[MAXN], w[MAXN];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> h[i];
    for (int i = 1; i <= n; i++) cin >> w[i];
    int ans = 0;
    for (int i = 1; i <= n; i++){
        ans = _add(ans, _mlt(C(h[i] + 1), C(w[i] + 1)));
    }
    for (int i = 1; i <= n; i++){
        int mn = h[i];
        for (int j = i + 1; j <= n; j++){
            mn = min(mn, h[j]);
            ans = _add(ans, _mlt(_mlt(w[i], w[j]), C(mn + 1)));
        }
    }
    cout << ans;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Execution timed out 1081 ms 1380 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 351 ms 604 KB Output is correct
3 Execution timed out 1083 ms 1736 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 496 KB Output is correct
3 Correct 346 ms 604 KB Output is correct
4 Execution timed out 1052 ms 1628 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 472 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Execution timed out 1092 ms 1296 KB Time limit exceeded
12 Halted 0 ms 0 KB -