제출 #1067122

#제출 시각아이디문제언어결과실행 시간메모리
10671220npataFlooding Wall (BOI24_wall)C++17
37 / 100
1260 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define vec vector const int MOD = 1e9+7; int MX = 10005; void add(int32_t& 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); bool flag = true; for(int i = 0; i<N; i++) { cin >> a[i]; flag &= a[i] <=2; }; for(int i = 0; i<N; i++) { cin >> b[i]; flag &= b[i] <=2; }; if(flag) MX = 4; set<int> vals; for(int i = 0; i<N; i++) { vals.insert(a[i]); vals.insert(b[i]); } int id = 0; vec<int> id_to_val(MX); map<int, int> val_to_id; for(int val : vals) { val_to_id[val] = id; id_to_val[id++] = val; } for(int i = 0; i<N; i++) { a[i] = val_to_id[a[i]]; b[i] = val_to_id[b[i]]; } vec<vec<int32_t>> mxcnt_left(N+2, vec<int32_t>(MX)); vec<vec<int32_t>> mxcnt_right(N+2, vec<int32_t>(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<int32_t>> mnmx_cnt(N+2, vec<int32_t>(MX)); for(int i = 1; i<=N; i++) { int32_t rightsum = 0; for(int j = MX-1; j>=0; j--) { add(rightsum, mxcnt_right[i+1][j]); add(mnmx_cnt[i][j], (int)(mxcnt_left[i-1][j]*(int)rightsum)%MOD); } int32_t leftsum = 0; for(int j = MX-1; j>=0; j--) { add(mnmx_cnt[i][j], ((int)mxcnt_right[i+1][j]*(int)leftsum)%MOD); add(leftsum, mxcnt_left[i-1][j]); } } int32_t ans = 0; for(int i = 1; i<=N; i++) { for(int j = a[i-1]; j<MX; j++) { add(ans, ((int)mnmx_cnt[i][j]*(int)(id_to_val[j]-id_to_val[a[i-1]]))%MOD); } for(int j = b[i-1]; j<MX; j++) { add(ans, ((int)mnmx_cnt[i][j]*(int)(id_to_val[j]-id_to_val[b[i-1]]))%MOD); } } 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...