Submission #1062069

# Submission time Handle Problem Language Result Execution time Memory
1062069 2024-08-16T18:17:36 Z Jarif_Rahman Flooding Wall (BOI24_wall) C++17
58 / 100
5000 ms 10076 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll md = 1e9+7;
const int N = 5e5+5;
const ll inv2 = 500000004;
ll pw2[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    pw2[0] = 1;
    for(int i = 1; i < N; i++) pw2[i] = (pw2[i-1]*2)%md;

    int n; cin >> n;
    vector<int> A(n), B(n);
    int m = 0;
    for(int &x: A) cin >> x, m = max(m, x);
    for(int &x: B) cin >> x, m = max(m, x);
    for(int i = 0; i < n; i++) if(A[i] > B[i]) swap(A[i], B[i]);

    ll ans = 0;

    auto solve = [&](int i, ll x){
        ll cur = 1, sum = 0;
        int c = 0;
        for(int j = i-1; j >= 0; j--){
            if(A[j] > x){
                cur = 0;
                break;
            }
            if(B[j] <= x) c++;
        }
        cur*=pw2[c], cur%=md;
        cur*=pw2[n-i-1], cur%=md;

        bool breaked = 0;
        for(int j = i+1; j < n; j++){
            if(B[j] < x) continue;
            if(A[j] >= x){
                ans+=((((j-i)*x)%md)*cur)%md, ans%=md;
                breaked = 1;
                break;
            }
            cur*=inv2, cur%=md;
            ans+=((((j-i)*x)%md)*cur)%md, ans%=md;
        }
        if(!breaked) ans+=(x*cur)%md, ans%=md;
    };

    auto solve_rev = [&](int i, ll x){
        ll cur = 1, sum = 0;
        int c = 0;
        for(int j = i+1; j < n; j++){
            if(A[j] >= x){
                cur = 0;
                break;
            }
            if(B[j] < x) c++;
        }
        cur*=pw2[c], cur%=md;
        cur*=pw2[i], cur%=md;

        for(int j = i-1; j >= 0; j--){
            if(B[j] <= x) continue;
            if(A[j] > x){
                ans+=((((i-j)*x)%md)*cur)%md, ans%=md;
                break;
            }
            cur*=inv2, cur%=md;
            ans+=((((i-j)*x)%md)*cur)%md, ans%=md;
        }
    };

    for(int i = 0; i < n; i++){
        solve(i, A[i]);
        solve(i, B[i]);
        solve_rev(i, A[i]);
        solve_rev(i, B[i]);
    }

    for(int i = 0; i < n; i++) ans-=((A[i]+B[i])*pw2[n-1])%md, ans%=md;
    if(ans < 0) ans+=md;

    cout << ans << "\n";
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:31:21: warning: unused variable 'sum' [-Wunused-variable]
   31 |         ll cur = 1, sum = 0;
      |                     ^~~
Main.cpp: In lambda function:
Main.cpp:58:21: warning: unused variable 'sum' [-Wunused-variable]
   58 |         ll cur = 1, sum = 0;
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 3 ms 4184 KB Output is correct
9 Correct 3 ms 4232 KB Output is correct
10 Correct 3 ms 4372 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 3 ms 4188 KB Output is correct
14 Correct 4 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 3 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 4 ms 4188 KB Output is correct
7 Correct 3 ms 4188 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 3 ms 4120 KB Output is correct
11 Correct 3 ms 4372 KB Output is correct
12 Correct 4 ms 4188 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 3 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 4 ms 4188 KB Output is correct
24 Correct 3 ms 4188 KB Output is correct
25 Correct 3 ms 4360 KB Output is correct
26 Correct 3 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 4 ms 4188 KB Output is correct
7 Correct 3 ms 4188 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 3 ms 4120 KB Output is correct
11 Correct 3 ms 4372 KB Output is correct
12 Correct 4 ms 4188 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 3 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 3 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 4 ms 4188 KB Output is correct
24 Correct 3 ms 4188 KB Output is correct
25 Correct 3 ms 4360 KB Output is correct
26 Correct 3 ms 4188 KB Output is correct
27 Correct 15 ms 4440 KB Output is correct
28 Correct 14 ms 4532 KB Output is correct
29 Correct 831 ms 4440 KB Output is correct
30 Correct 823 ms 4472 KB Output is correct
31 Correct 79 ms 4440 KB Output is correct
32 Correct 81 ms 4444 KB Output is correct
33 Correct 89 ms 4444 KB Output is correct
34 Correct 89 ms 4476 KB Output is correct
35 Correct 83 ms 4440 KB Output is correct
36 Correct 84 ms 4440 KB Output is correct
37 Correct 839 ms 4688 KB Output is correct
38 Correct 878 ms 4468 KB Output is correct
39 Correct 82 ms 4440 KB Output is correct
40 Correct 80 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 3 ms 4184 KB Output is correct
9 Correct 3 ms 4232 KB Output is correct
10 Correct 3 ms 4372 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 3 ms 4188 KB Output is correct
14 Correct 4 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 3 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4376 KB Output is correct
23 Correct 3 ms 4188 KB Output is correct
24 Correct 3 ms 4188 KB Output is correct
25 Correct 3 ms 4188 KB Output is correct
26 Correct 3 ms 4188 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 3 ms 4188 KB Output is correct
31 Correct 3 ms 4188 KB Output is correct
32 Correct 3 ms 4120 KB Output is correct
33 Correct 3 ms 4372 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 3 ms 4188 KB Output is correct
37 Correct 3 ms 4188 KB Output is correct
38 Correct 3 ms 4188 KB Output is correct
39 Correct 3 ms 4188 KB Output is correct
40 Correct 3 ms 4444 KB Output is correct
41 Correct 3 ms 4188 KB Output is correct
42 Correct 3 ms 4188 KB Output is correct
43 Correct 3 ms 4188 KB Output is correct
44 Correct 3 ms 4188 KB Output is correct
45 Correct 4 ms 4188 KB Output is correct
46 Correct 3 ms 4188 KB Output is correct
47 Correct 3 ms 4360 KB Output is correct
48 Correct 3 ms 4188 KB Output is correct
49 Correct 15 ms 4440 KB Output is correct
50 Correct 14 ms 4532 KB Output is correct
51 Correct 831 ms 4440 KB Output is correct
52 Correct 823 ms 4472 KB Output is correct
53 Correct 79 ms 4440 KB Output is correct
54 Correct 81 ms 4444 KB Output is correct
55 Correct 89 ms 4444 KB Output is correct
56 Correct 89 ms 4476 KB Output is correct
57 Correct 83 ms 4440 KB Output is correct
58 Correct 84 ms 4440 KB Output is correct
59 Correct 839 ms 4688 KB Output is correct
60 Correct 878 ms 4468 KB Output is correct
61 Correct 82 ms 4440 KB Output is correct
62 Correct 80 ms 4440 KB Output is correct
63 Correct 16 ms 4444 KB Output is correct
64 Correct 14 ms 4444 KB Output is correct
65 Correct 83 ms 4640 KB Output is correct
66 Correct 79 ms 4444 KB Output is correct
67 Correct 82 ms 4444 KB Output is correct
68 Correct 100 ms 4444 KB Output is correct
69 Correct 489 ms 4444 KB Output is correct
70 Correct 503 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4444 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 3 ms 4188 KB Output is correct
8 Correct 3 ms 4200 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 861 ms 4468 KB Output is correct
11 Correct 827 ms 4440 KB Output is correct
12 Correct 870 ms 4444 KB Output is correct
13 Correct 845 ms 4468 KB Output is correct
14 Execution timed out 5065 ms 10076 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 3 ms 4184 KB Output is correct
9 Correct 3 ms 4232 KB Output is correct
10 Correct 3 ms 4372 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 3 ms 4188 KB Output is correct
14 Correct 4 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 3 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4376 KB Output is correct
23 Correct 3 ms 4188 KB Output is correct
24 Correct 3 ms 4188 KB Output is correct
25 Correct 3 ms 4188 KB Output is correct
26 Correct 3 ms 4188 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 3 ms 4188 KB Output is correct
31 Correct 3 ms 4188 KB Output is correct
32 Correct 3 ms 4120 KB Output is correct
33 Correct 3 ms 4372 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 3 ms 4188 KB Output is correct
37 Correct 3 ms 4188 KB Output is correct
38 Correct 3 ms 4188 KB Output is correct
39 Correct 3 ms 4188 KB Output is correct
40 Correct 3 ms 4444 KB Output is correct
41 Correct 3 ms 4188 KB Output is correct
42 Correct 3 ms 4188 KB Output is correct
43 Correct 3 ms 4188 KB Output is correct
44 Correct 3 ms 4188 KB Output is correct
45 Correct 4 ms 4188 KB Output is correct
46 Correct 3 ms 4188 KB Output is correct
47 Correct 3 ms 4360 KB Output is correct
48 Correct 3 ms 4188 KB Output is correct
49 Correct 15 ms 4440 KB Output is correct
50 Correct 14 ms 4532 KB Output is correct
51 Correct 831 ms 4440 KB Output is correct
52 Correct 823 ms 4472 KB Output is correct
53 Correct 79 ms 4440 KB Output is correct
54 Correct 81 ms 4444 KB Output is correct
55 Correct 89 ms 4444 KB Output is correct
56 Correct 89 ms 4476 KB Output is correct
57 Correct 83 ms 4440 KB Output is correct
58 Correct 84 ms 4440 KB Output is correct
59 Correct 839 ms 4688 KB Output is correct
60 Correct 878 ms 4468 KB Output is correct
61 Correct 82 ms 4440 KB Output is correct
62 Correct 80 ms 4440 KB Output is correct
63 Correct 16 ms 4444 KB Output is correct
64 Correct 14 ms 4444 KB Output is correct
65 Correct 83 ms 4640 KB Output is correct
66 Correct 79 ms 4444 KB Output is correct
67 Correct 82 ms 4444 KB Output is correct
68 Correct 100 ms 4444 KB Output is correct
69 Correct 489 ms 4444 KB Output is correct
70 Correct 503 ms 4548 KB Output is correct
71 Correct 3 ms 4444 KB Output is correct
72 Correct 3 ms 4188 KB Output is correct
73 Correct 3 ms 4188 KB Output is correct
74 Correct 3 ms 4188 KB Output is correct
75 Correct 3 ms 4188 KB Output is correct
76 Correct 3 ms 4188 KB Output is correct
77 Correct 3 ms 4188 KB Output is correct
78 Correct 3 ms 4200 KB Output is correct
79 Correct 3 ms 4188 KB Output is correct
80 Correct 861 ms 4468 KB Output is correct
81 Correct 827 ms 4440 KB Output is correct
82 Correct 870 ms 4444 KB Output is correct
83 Correct 845 ms 4468 KB Output is correct
84 Execution timed out 5065 ms 10076 KB Time limit exceeded
85 Halted 0 ms 0 KB -