답안 #881603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881603 2023-12-01T15:24:03 Z Iliya_ Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
21 ms 7336 KB
//IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#define endl        '\n'
#define F           first
#define S           second
#define pii         pair<int,int>
#define all(x)      x.begin(),x.end()
#define pb          push_back
#define fast_io     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define file_io     freopen("input.in" , "r" , stdin) ; freopen("output.out" , "w" , stdout);
using namespace std;
typedef long long ll; 
typedef long double dll;

#define int long long
const int N = 1e5+7, mod = 1e9+7;
int h[N], w[N], sumw[N], dp[N], ans[N], inv2; 
vector<pii> vec; 

int power(int a, int b){
     int ans = 1;
     while(b){
          if (b&1) ans = ans * a % mod; 
          a = a * a % mod; 
          b /= 2; 
     }
     return ans; 
}

int f(int x){
     return (x * (x-1) % mod * inv2 % mod);
}

int32_t main(){
     fast_io; 

     inv2 = power(2,mod-2); 
     int n; cin >> n; 
     for(int i=1; i<=n; i++) cin >> h[i]; 
     for(int i=1; i<=n; i++){
          cin >> w[i]; 
          sumw[i] = (sumw[i-1] + w[i]) % mod; 
     }
     dp[0] = ans[0] = 0;
     vec.pb({0,0}); 
     for(int i=1; i<=n; i++){
          while(vec.back().F >= h[i]) vec.pop_back();
          int ind = vec.back().S;
          vec.pb({h[i],i}); 
          int majw = (sumw[i-1] - sumw[ind] + mod) % mod, majw2 = (sumw[i] - sumw[ind] + mod)%mod;   
          dp[i] = (dp[ind] + f(h[i]+1) * majw2 % mod) %mod;
          ans[i] = (dp[ind] * w[i] % mod + f(h[i]+1) * f(w[i]+1) % mod + f(h[i]+1) * w[i] % mod * majw % mod)%mod; 
     }
     int out = 0; 
     for(int i=1; i<=n; i++) out = (out + ans[i]) % mod; 
     cout << out << endl;

     return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 8 ms 2908 KB Output is correct
4 Correct 16 ms 4960 KB Output is correct
5 Correct 17 ms 4956 KB Output is correct
6 Correct 16 ms 4884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 848 KB Output is correct
3 Correct 11 ms 3204 KB Output is correct
4 Correct 21 ms 5460 KB Output is correct
5 Correct 21 ms 5456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 988 KB Output is correct
4 Correct 11 ms 3184 KB Output is correct
5 Correct 21 ms 5456 KB Output is correct
6 Correct 20 ms 5436 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 11 ms 3656 KB Output is correct
10 Correct 20 ms 7284 KB Output is correct
11 Correct 21 ms 7144 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 8 ms 2908 KB Output is correct
12 Correct 16 ms 4976 KB Output is correct
13 Correct 17 ms 5096 KB Output is correct
14 Correct 16 ms 4956 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 10 ms 2976 KB Output is correct
18 Correct 20 ms 5448 KB Output is correct
19 Correct 21 ms 5600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 1248 KB Output is correct
22 Correct 13 ms 3548 KB Output is correct
23 Correct 21 ms 7336 KB Output is correct
24 Correct 21 ms 7120 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 540 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 10 ms 3164 KB Output is correct
33 Correct 11 ms 3056 KB Output is correct
34 Correct 19 ms 5212 KB Output is correct
35 Correct 19 ms 5212 KB Output is correct
36 Correct 21 ms 5392 KB Output is correct
37 Correct 20 ms 5460 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 20 ms 5640 KB Output is correct
40 Correct 20 ms 5504 KB Output is correct
41 Correct 20 ms 5680 KB Output is correct
42 Correct 20 ms 6356 KB Output is correct