답안 #1003412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003412 2024-06-20T09:59:38 Z vjudge1 Flooding Wall (BOI24_wall) C++17
44 / 100
2705 ms 158408 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

const int N = 1e4+4, M = 2e3+3, mod = 1e9+7;

int n, mx, a[N], b[N], c[N], pre[M][N], suf[M][N], pre2[N], suf2[N];

int pw(int x, int y) {
  return (!y ? 1 : pw(x*x % mod, y/2) * (y%2 ? x : 1) % mod);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  mx = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] > b[i]) swap(a[i], b[i]);
    mx = max(mx, b[i]);
  }
  mx += 6;

  if (n <= 20) {
    int ans = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
      for (int i = 0; i < n; i++) {
        c[i] = a[i];

        if ((mask >> i) & 1) c[i] = b[i];
      }

      for (int i = 0; i < n; i++) {
        pre2[i] = max((i ? pre2[i-1] : 1), c[i]);
      }

      for (int i = n-1; i >= 0; i--) {
        suf2[i] = max((i+1 < n ? suf2[i+1] : 1), c[i]);
      }

      for (int i = 1; i < n-1; i++) {
        if (c[i] < min(pre2[i-1], suf2[i+1])) {
          ans += min(pre2[i-1], suf2[i+1]) - c[i];
          ans %= mod;
        }
      }
    }

    cout << ans << "\n";
  }
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= mx; j++) {
        pre[j][i] = (i ? pre[j][i-1] : 1);
        
        if (b[i] <= j) {
          pre[j][i] *= 2;
          pre[j][i] %= mod;
        }
        else if (a[i] > j) pre[j][i] = 0;
      }
    }

    for (int i = n-1; i >= 0; i--) {
      for (int j = 0; j <= mx; j++) {
        suf[j][i] = (i+1 < n ? suf[j][i+1] : 1);
        
        if (b[i] <= j) {
          suf[j][i] *= 2;
          suf[j][i] %= mod;
        }
        else if (a[i] > j) suf[j][i] = 0;
      }
    }

    int ans = 0;
    for (int i = 1; i < n-1; i++) {
      for (int j = 0; j <= mx; j++) {
        int x = 0;

        x += pw(2, n-1-i) * pre[j-1][i-1] % mod;
        x %= mod;

        x += pw(2, i) * suf[j-1][i+1] % mod;
        x %= mod;

        x = (x - pre[j-1][i-1] * suf[j-1][i+1] % mod + mod) % mod;
        
        //cerr << i << " " << j << " " << x << endl;

        if (a[i] < j) {
          ans += (pw(2, n-1) - x + mod) % mod;
          ans %= mod;
        }

        if (b[i] < j) {
          ans += (pw(2, n-1) - x + mod) % mod;
          ans %= mod;
        }
      }
    }

    cout << ans << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 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 129 ms 348 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 171 ms 596 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 128 ms 348 KB Output is correct
17 Correct 141 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 15 ms 476 KB Output is correct
21 Correct 134 ms 344 KB Output is correct
22 Correct 67 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 348 KB Output is correct
4 Correct 0 ms 352 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 165 ms 348 KB Output is correct
12 Correct 5 ms 348 KB Output is correct
13 Correct 116 ms 452 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 9 ms 10076 KB Output is correct
16 Correct 9 ms 10348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 10 ms 10348 KB Output is correct
21 Correct 12 ms 10332 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 8 ms 10332 KB Output is correct
24 Correct 12 ms 10076 KB Output is correct
25 Correct 11 ms 10352 KB Output is correct
26 Correct 10 ms 10348 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 348 KB Output is correct
4 Correct 0 ms 352 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 165 ms 348 KB Output is correct
12 Correct 5 ms 348 KB Output is correct
13 Correct 116 ms 452 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 9 ms 10076 KB Output is correct
16 Correct 9 ms 10348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 10 ms 10348 KB Output is correct
21 Correct 12 ms 10332 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 8 ms 10332 KB Output is correct
24 Correct 12 ms 10076 KB Output is correct
25 Correct 11 ms 10352 KB Output is correct
26 Correct 10 ms 10348 KB Output is correct
27 Correct 2080 ms 158292 KB Output is correct
28 Correct 2109 ms 158400 KB Output is correct
29 Correct 23 ms 1884 KB Output is correct
30 Correct 23 ms 1880 KB Output is correct
31 Correct 41 ms 3160 KB Output is correct
32 Correct 1300 ms 158408 KB Output is correct
33 Correct 2705 ms 157552 KB Output is correct
34 Correct 54 ms 3160 KB Output is correct
35 Correct 1339 ms 158236 KB Output is correct
36 Correct 2585 ms 158296 KB Output is correct
37 Correct 23 ms 1884 KB Output is correct
38 Correct 24 ms 2136 KB Output is correct
39 Correct 36 ms 3164 KB Output is correct
40 Correct 37 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 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 129 ms 348 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 171 ms 596 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 128 ms 348 KB Output is correct
17 Correct 141 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 15 ms 476 KB Output is correct
21 Correct 134 ms 344 KB Output is correct
22 Correct 67 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 165 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 116 ms 452 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 9 ms 10076 KB Output is correct
38 Correct 9 ms 10348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 10 ms 10348 KB Output is correct
43 Correct 12 ms 10332 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 8 ms 10332 KB Output is correct
46 Correct 12 ms 10076 KB Output is correct
47 Correct 11 ms 10352 KB Output is correct
48 Correct 10 ms 10348 KB Output is correct
49 Correct 2080 ms 158292 KB Output is correct
50 Correct 2109 ms 158400 KB Output is correct
51 Correct 23 ms 1884 KB Output is correct
52 Correct 23 ms 1880 KB Output is correct
53 Correct 41 ms 3160 KB Output is correct
54 Correct 1300 ms 158408 KB Output is correct
55 Correct 2705 ms 157552 KB Output is correct
56 Correct 54 ms 3160 KB Output is correct
57 Correct 1339 ms 158236 KB Output is correct
58 Correct 2585 ms 158296 KB Output is correct
59 Correct 23 ms 1884 KB Output is correct
60 Correct 24 ms 2136 KB Output is correct
61 Correct 36 ms 3164 KB Output is correct
62 Correct 37 ms 3160 KB Output is correct
63 Runtime error 23 ms 18012 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 185 ms 348 KB Output is correct
7 Correct 5 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 23 ms 2084 KB Output is correct
11 Correct 23 ms 1884 KB Output is correct
12 Correct 24 ms 1884 KB Output is correct
13 Correct 23 ms 1884 KB Output is correct
14 Incorrect 1 ms 632 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 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 129 ms 348 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 171 ms 596 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 128 ms 348 KB Output is correct
17 Correct 141 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 15 ms 476 KB Output is correct
21 Correct 134 ms 344 KB Output is correct
22 Correct 67 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 165 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 116 ms 452 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 9 ms 10076 KB Output is correct
38 Correct 9 ms 10348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 10 ms 10348 KB Output is correct
43 Correct 12 ms 10332 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 8 ms 10332 KB Output is correct
46 Correct 12 ms 10076 KB Output is correct
47 Correct 11 ms 10352 KB Output is correct
48 Correct 10 ms 10348 KB Output is correct
49 Correct 2080 ms 158292 KB Output is correct
50 Correct 2109 ms 158400 KB Output is correct
51 Correct 23 ms 1884 KB Output is correct
52 Correct 23 ms 1880 KB Output is correct
53 Correct 41 ms 3160 KB Output is correct
54 Correct 1300 ms 158408 KB Output is correct
55 Correct 2705 ms 157552 KB Output is correct
56 Correct 54 ms 3160 KB Output is correct
57 Correct 1339 ms 158236 KB Output is correct
58 Correct 2585 ms 158296 KB Output is correct
59 Correct 23 ms 1884 KB Output is correct
60 Correct 24 ms 2136 KB Output is correct
61 Correct 36 ms 3164 KB Output is correct
62 Correct 37 ms 3160 KB Output is correct
63 Runtime error 23 ms 18012 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -