Submission #1062073

# Submission time Handle Problem Language Result Execution time Memory
1062073 2024-08-16T18:23:59 Z Jarif_Rahman Flooding Wall (BOI24_wall) C++17
48 / 100
390 ms 1048576 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;
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]);

    m++;
    vector<int> cmnl(m, 0), cmxl(m, 0), cmnr(m, 0), cmxr(m, 0);
    for(int i = 0; i < n; i++) cmnr[A[i]]++, cmxr[B[i]]++;

    ll ans = 0;
    for(int i = 0; i+1 < n; i++){
        cmnr[A[i]]--, cmxr[B[i]]--;
        int xl = 0, yl = 0, xr = 0, yr = 0;
        for(int j = m-1; j > A[i]; j--){
            xl+=cmnl[j], yl+=cmxl[j], xr+=cmnr[j], yr+=cmxr[j];
            ll cur = 2;
            if(j <= B[i]) cur = 1;

            if(xl > 0) cur*=pw2[i], cur%=md;
            else cur*=(pw2[i-yl]*(pw2[yl]-1))%md, cur%=md;

            if(xr > 0) cur*=pw2[n-i-1], cur%=md;
            else cur*=(pw2[n-i-1-yr]*(pw2[yr]-1))%md, cur%=md;

            ans+=cur, ans%=md;
        }
        cmnl[A[i]]++, cmxl[B[i]]++;
    }

    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 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 4 ms 4184 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 3 ms 4188 KB Output is correct
11 Runtime error 390 ms 1048576 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4188 KB Output is correct
2 Correct 3 ms 4312 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4140 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 4 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4184 KB Output is correct
12 Correct 3 ms 4160 KB Output is correct
13 Correct 3 ms 4188 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 4224 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 4188 KB Output is correct
23 Correct 3 ms 4188 KB Output is correct
24 Correct 4 ms 4188 KB Output is correct
25 Correct 4 ms 4188 KB Output is correct
26 Correct 4 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4188 KB Output is correct
2 Correct 3 ms 4312 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4140 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 4 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4184 KB Output is correct
12 Correct 3 ms 4160 KB Output is correct
13 Correct 3 ms 4188 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 4224 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 4188 KB Output is correct
23 Correct 3 ms 4188 KB Output is correct
24 Correct 4 ms 4188 KB Output is correct
25 Correct 4 ms 4188 KB Output is correct
26 Correct 4 ms 4188 KB Output is correct
27 Correct 39 ms 4440 KB Output is correct
28 Correct 38 ms 4440 KB Output is correct
29 Correct 4 ms 4440 KB Output is correct
30 Correct 4 ms 4444 KB Output is correct
31 Correct 4 ms 4444 KB Output is correct
32 Correct 5 ms 4456 KB Output is correct
33 Correct 56 ms 4420 KB Output is correct
34 Correct 4 ms 4444 KB Output is correct
35 Correct 5 ms 4224 KB Output is correct
36 Correct 55 ms 4444 KB Output is correct
37 Correct 4 ms 4444 KB Output is correct
38 Correct 4 ms 4308 KB Output is correct
39 Correct 5 ms 4456 KB Output is correct
40 Correct 4 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 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 4 ms 4184 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 3 ms 4188 KB Output is correct
11 Runtime error 390 ms 1048576 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 3 ms 4228 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 4440 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 4184 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 4 ms 4444 KB Output is correct
11 Correct 4 ms 4440 KB Output is correct
12 Correct 4 ms 4696 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 43 ms 8284 KB Output is correct
15 Correct 45 ms 10080 KB Output is correct
16 Correct 46 ms 10060 KB Output is correct
17 Correct 44 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 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 4 ms 4184 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 3 ms 4188 KB Output is correct
11 Runtime error 390 ms 1048576 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -