Submission #555333

# Submission time Handle Problem Language Result Execution time Memory
555333 2022-04-30T13:25:56 Z 600Mihnea Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
29 ms 3152 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

typedef long long ll;
const int N=(int)1e5+7;
const ll INF=(ll)1e18+7;
int n;
int m;
ll a[N];
ll b[N];


signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif
  home = 0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  vector<int> shib_a, shib_b;
  cin>>n>>m;
  for (int i=1;i<=n;i++) {
    cin>>a[i];
    while (1) {
      if((int)shib_a.size()<2) break;
      int p1=shib_a[(int)shib_a.size()-2];
      int p2=shib_a[(int)shib_a.size()-1];
      if((a[i]-a[p2])*(p2-p1)<(a[p2]-a[p1])*(i-p2)) {
        shib_a.pop_back();
      }else{
        break;
      }
    }
    shib_a.push_back(i);
  }
  for (int i=1;i<=m;i++) {
    cin>>b[i];
    while (1) {
      if((int)shib_b.size()<2) break;
      int p1=shib_b[(int)shib_b.size()-2];
      int p2=shib_b[(int)shib_b.size()-1];
      if((b[i]-b[p2])*(p2-p1)<(b[p2]-b[p1])*(i-p2)) {
        shib_b.pop_back();
      }else{
        break;
      }
    }
    shib_b.push_back(i);
  }
  n=(int)shib_a.size()-1;
  m=(int)shib_b.size()-1;
  ll sol=0;
  int i=0,j=0;
  while(i<n||j<m){
    bool dojo=0;
    if(i==n){
      dojo=1;
    }else{
      if(j==m){
        dojo=0;
      }else{
        assert(i<n&&j<m);
        ll a1=shib_a[i];
        ll a2=shib_a[i+1];
        ll b1=shib_b[j];
        ll b2=shib_b[j+1];
        if((a[a2]-a[a1])*(b2-b1)>(b[b2]-b[b1])*(a2-a1)){
          dojo=1;
        }else{
          dojo=0;
        }
      }
    }
    if(dojo==0){
      assert(i<n);
      sol+=(shib_a[i+1]-shib_a[i])*b[shib_b[j]];
      i++;
    }else{
      assert(j<m);
      sol+=(shib_b[j+1]-shib_b[j])*a[shib_a[i]];
      j++;
    }
  }
  cout<<sol<<"\n";

}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 7 ms 1216 KB Output is correct
5 Correct 6 ms 1116 KB Output is correct
6 Correct 3 ms 668 KB Output is correct
7 Correct 17 ms 2220 KB Output is correct
8 Correct 17 ms 2228 KB Output is correct
9 Correct 16 ms 2212 KB Output is correct
10 Correct 17 ms 2184 KB Output is correct
11 Correct 14 ms 2252 KB Output is correct
12 Correct 16 ms 2228 KB Output is correct
13 Correct 16 ms 2252 KB Output is correct
14 Correct 14 ms 2296 KB Output is correct
15 Correct 17 ms 3152 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 7 ms 1216 KB Output is correct
33 Correct 6 ms 1116 KB Output is correct
34 Correct 3 ms 668 KB Output is correct
35 Correct 17 ms 2220 KB Output is correct
36 Correct 17 ms 2228 KB Output is correct
37 Correct 16 ms 2212 KB Output is correct
38 Correct 17 ms 2184 KB Output is correct
39 Correct 14 ms 2252 KB Output is correct
40 Correct 16 ms 2228 KB Output is correct
41 Correct 16 ms 2252 KB Output is correct
42 Correct 14 ms 2296 KB Output is correct
43 Correct 17 ms 3152 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 12 ms 1356 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 4 ms 700 KB Output is correct
59 Correct 24 ms 2244 KB Output is correct
60 Correct 27 ms 2248 KB Output is correct
61 Correct 25 ms 2252 KB Output is correct
62 Correct 24 ms 2280 KB Output is correct
63 Correct 29 ms 3024 KB Output is correct
64 Correct 29 ms 2188 KB Output is correct
65 Correct 27 ms 2384 KB Output is correct
66 Correct 23 ms 2240 KB Output is correct
67 Correct 28 ms 3108 KB Output is correct