Submission #712615

# Submission time Handle Problem Language Result Execution time Memory
712615 2023-03-19T10:03:03 Z konstantys Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
131 ms 11320 KB
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<queue>
#define f first
#define s second
using namespace std;
struct ulamek{
  long long a,b;
};
bool operator== (ulamek a,ulamek b){
  return a.a*b.b==a.b*b.a;
}
bool operator< (ulamek a,ulamek b){
  return a.a*b.b<b.a*a.b;
}
ulamek mul(int a,int b){
  ulamek c;
  c.a=a,c.b=b;
  return c;
}
priority_queue <pair<ulamek,pair<int,int>>> s;
//using namespace std;
long long tab[2][100005];
int kol[2][100005],przed[2][100005];
int h,w;
long long wyn;
bool us[2][100005];
int main(){
  ios_base::sync_with_stdio(0);
  cin>>h>>w;
  for(int i=0;i<h;i++) cin>>tab[0][i];
  for(int i=0;i<w;i++) cin>>tab[1][i];
  przed[0][0]=-1;
  kol[0][h-1]=-1;
  for(int i=1;i<h;i++){
    kol[0][i-1]=i;
    przed[0][i]=i-1;
    s.push({mul(tab[0][i]-tab[0][i-1],1),{i-1,i}});
  }
  przed[1][0]=-1;
  kol[1][w-1]=-1;
  for(int i=1;i<w;i++){
    kol[1][i-1]=i;
    przed[1][i]=i-1;
    s.push({mul(tab[1][i]-tab[1][i-1],1),{1-i,-i}});
  }
  int h2=h,w2=w;
  while(!s.empty()){
    auto i=s.top();
    s.pop();
    int pom=0;
    if(i.s.f<0 || i.s.s<0) i.s.f=-i.s.f,i.s.s=-i.s.s,pom=1;
    if(us[pom][i.s.f] || us[pom][i.s.s]) continue;
    int a=przed[pom][i.s.s],b=kol[pom][i.s.s];
    if(a!=-1) kol[pom][a]=b;
    if(b!=-1) przed[pom][b]=a;
    us[pom][i.s.s]=1;
    if(a!=-1 && b!=-1)
    s.push({mul(tab[pom][b]-tab[pom][a],b-a),{(1-2*pom)*a,(1-2*pom)*b}});
    if(pom==0){
      if(h-1==i.s.s){
        h=i.s.f+1;
        wyn+=tab[1][w-1]*(i.s.s-i.s.f);
      }
    }else{
      if(w-1==i.s.s){
        w=i.s.f+1;
        wyn+=tab[0][h-1]*(i.s.s-i.s.f);
      }
    }
    if(h==1 && w==1) break;
    /*
    cerr<<pom<<" "<<i.s.s<<"\n";
    //pair<ulamek,int> i=* s.rbegin();
    for(int i=0;i<h2;i++) cerr<<us[0][i];
    cerr<<"\n";
    for(int i=0;i<w2;i++) cerr<<us[1][i];
    cerr<<"\n\n";
    // */
  }
  //cerr<<h<<" "<<w<<"\n";
  cout<<wyn<<"\n";
  return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:48:7: warning: unused variable 'h2' [-Wunused-variable]
   48 |   int h2=h,w2=w;
      |       ^~
kyoto.cpp:48:12: warning: unused variable 'w2' [-Wunused-variable]
   48 |   int h2=h,w2=w;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 44 ms 4988 KB Output is correct
5 Correct 27 ms 4936 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 131 ms 9884 KB Output is correct
8 Correct 111 ms 9872 KB Output is correct
9 Correct 128 ms 9984 KB Output is correct
10 Correct 122 ms 9996 KB Output is correct
11 Correct 74 ms 9844 KB Output is correct
12 Correct 129 ms 9916 KB Output is correct
13 Correct 123 ms 9968 KB Output is correct
14 Correct 87 ms 10008 KB Output is correct
15 Correct 52 ms 10100 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 44 ms 4988 KB Output is correct
33 Correct 27 ms 4936 KB Output is correct
34 Correct 17 ms 2636 KB Output is correct
35 Correct 131 ms 9884 KB Output is correct
36 Correct 111 ms 9872 KB Output is correct
37 Correct 128 ms 9984 KB Output is correct
38 Correct 122 ms 9996 KB Output is correct
39 Correct 74 ms 9844 KB Output is correct
40 Correct 129 ms 9916 KB Output is correct
41 Correct 123 ms 9968 KB Output is correct
42 Correct 87 ms 10008 KB Output is correct
43 Correct 52 ms 10100 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 324 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 324 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 48 ms 5516 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 4 ms 1044 KB Output is correct
58 Correct 13 ms 1860 KB Output is correct
59 Correct 130 ms 11108 KB Output is correct
60 Correct 117 ms 11048 KB Output is correct
61 Correct 127 ms 11168 KB Output is correct
62 Correct 126 ms 11104 KB Output is correct
63 Correct 70 ms 11068 KB Output is correct
64 Correct 127 ms 11068 KB Output is correct
65 Correct 130 ms 11080 KB Output is correct
66 Correct 88 ms 11068 KB Output is correct
67 Correct 57 ms 11320 KB Output is correct