Submission #1067080

#TimeUsernameProblemLanguageResultExecution timeMemory
10670800npataFlooding Wall (BOI24_wall)C++17
36 / 100
439 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define vec vector const int MOD = 1e9+7; const int MX = 1'005; void add(int& a, int val) { a += val; a %= MOD; } void mul(int& a, int val) { a *= val; a %= MOD; } int32_t main() { int N; cin >> N; vec<int> A(N), B(N); for(int i = 0; i<N; i++) { cin >> A[i]; }; for(int i = 0; i<N; i++) { cin >> B[i]; }; vec<vec<int>> mxcnt_left(N+2, vec<int>(MX)); vec<vec<int>> mxcnt_right(N+2, vec<int>(MX)); mxcnt_left[0][0] = 1; for(int i = 1; i<=N; i++) { for(int j = 0; j<MX; j++) { add(mxcnt_left[i][max(A[i-1], j)], mxcnt_left[i-1][j]); add(mxcnt_left[i][max(B[i-1], j)], mxcnt_left[i-1][j]); } } mxcnt_right[N+1][0] = 1; for(int i = N; i>=1; i--) { for(int j = 0; j<MX; j++) { add(mxcnt_right[i][max(A[i-1], j)], mxcnt_right[i+1][j]); add(mxcnt_right[i][max(B[i-1], j)], mxcnt_right[i+1][j]); } } vec<vec<int>> mnmx_cnt(N+2, vec<int>(MX)); for(int i = 1; i<=N; i++) { int rightsum = 0; for(int j = MX-1; j>=0; j--) { add(rightsum, mxcnt_right[i+1][j]); add(mnmx_cnt[i][j], (mxcnt_left[i-1][j]*rightsum)%MOD); } int leftsum = 0; for(int j = MX-1; j>=0; j--) { add(mnmx_cnt[i][j], (mxcnt_right[i+1][j]*leftsum)%MOD); add(leftsum, mxcnt_left[i-1][j]); } } int ans = 0; for(int i = 1; i<=N; i++) { for(int j = A[i-1]; j<MX; j++) { add(ans, mnmx_cnt[i][j]*(j-A[i-1])); } for(int j = B[i-1]; j<MX; j++) { add(ans, mnmx_cnt[i][j]*(j-B[i-1])); } } cout << ans << '\n'; }
#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...