Submission #1113246

# Submission time Handle Problem Language Result Execution time Memory
1113246 2024-11-16T08:10:41 Z ntdaccode Real Mountains (CCO23_day1problem2) C++17
6 / 25
21 ms 4856 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i = a;i <= b; i++)
#define int long long
#define pb push_back
using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 1e6 + 10;
const int N = 5e3 + 10;
const int mod = 1e6 + 3;

int n,h[N];
int target[N];
vector<int> Q[N];
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if(fopen("1.inp","r"))
  {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }
  #define task ""
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n;
  for(int i = 1;i <= n; i++) cin >> h[i];

  int suf = 0,pre = 0;
  for(int i = 1;i <= n; i++) {
    pre = max(pre, h[i]);
    target[i] =  pre ;
  }
  for(int i = n; i != 0; i--) {
    suf = max(suf, h[i]);
    target[i] = min(target[i], suf);
  }
  for(int i = 1;i <= n; i++) {
    if(h[i] != target[i]) {
      Q[h[i]].pb(i);
    }
  }
  int kq = 0;
  for(int high = 1;high <= 100; high++) {
    if(Q[high].size() == 0) continue;
    if(Q[high].size() == 1) {
      int x = 1e9 , y = 1e9 , cur = Q[high][0];
      for(int j = 1; j < cur; j++) {
        if(h[j] > h[cur]) x = min(x,h[j]);
      }
      for(int j = cur + 1; j <= n ;j++) {
        if(h[j] > h[cur]) y = min(y,h[j]);
      }
      kq += x + y + high;
      kq %= mod;
      h[cur]++;
      if(h[cur] != target[cur]) Q[h[cur]].pb(cur);

    }
    else {
      sort(Q[high].begin(),Q[high].end());
      int pre_l = 1e9 , pre_r = 1e9 , suf_l = 1e9 , suf_r = 1e9;
      int l = Q[high][0], r = Q[high].back();
      for(int j = 1;j < l ; j++) {
        if(h[j] > h[l]) pre_l = min(pre_l,h[j]);
      }
      for(int j = l + 1;j <= n; j++) {
        if(h[j] > h[l]) suf_l = min(suf_l,h[j]);
      }
      for(int j = 1; j < r; j++) {
        if(h[j] > h[r]) pre_r = min(pre_r,h[j]);
      }
      for(int j = r + 1;j <= n; j++) {
        if(h[j] > h[r]) suf_r = min(suf_r,h[j]);
      }

      kq += min(pre_l + suf_l + h[l] + h[r] + h[l] + 1 + suf_r,
                pre_r + suf_r + h[r] + h[l] + h[r] + 1 + pre_l);
      kq %= mod;
      int sz = Q[high].size();
      kq += (sz - 2) * (high + 2 * (high + 1));
      kq %= mod;
      for(int idx : Q[high]) {
          h[idx]++;
          if(h[idx] != target[idx]) Q[h[idx]].pb(idx);
      }
    }
  }
  cout << kq % mod;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Runtime error 3 ms 1016 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Runtime error 3 ms 1016 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Incorrect 2 ms 600 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Runtime error 3 ms 1016 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 21 ms 2904 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 11 ms 4804 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 16 ms 2892 KB Output is correct
12 Correct 7 ms 2896 KB Output is correct
13 Correct 15 ms 2896 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 16 ms 2900 KB Output is correct
17 Correct 16 ms 2896 KB Output is correct
18 Correct 16 ms 2896 KB Output is correct
19 Correct 15 ms 2896 KB Output is correct
20 Correct 11 ms 4692 KB Output is correct
21 Correct 13 ms 4856 KB Output is correct
22 Correct 15 ms 4652 KB Output is correct
23 Correct 14 ms 2896 KB Output is correct
24 Correct 14 ms 2896 KB Output is correct
25 Correct 13 ms 2908 KB Output is correct
26 Correct 11 ms 2896 KB Output is correct
27 Correct 11 ms 2908 KB Output is correct
28 Correct 11 ms 2896 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Runtime error 3 ms 1016 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -