Submission #708824

# Submission time Handle Problem Language Result Execution time Memory
708824 2023-03-12T11:56:32 Z konstantys Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
141 ms 11376 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 324 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 324 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 468 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 2 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 472 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 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 456 KB Output is correct
4 Correct 43 ms 4936 KB Output is correct
5 Correct 29 ms 4900 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 127 ms 9976 KB Output is correct
8 Correct 114 ms 9924 KB Output is correct
9 Correct 126 ms 9932 KB Output is correct
10 Correct 130 ms 9992 KB Output is correct
11 Correct 71 ms 9856 KB Output is correct
12 Correct 127 ms 9984 KB Output is correct
13 Correct 133 ms 9948 KB Output is correct
14 Correct 83 ms 9916 KB Output is correct
15 Correct 46 ms 10120 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 340 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 328 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 328 KB Output is correct
26 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 324 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 324 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 468 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 2 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 472 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 456 KB Output is correct
32 Correct 43 ms 4936 KB Output is correct
33 Correct 29 ms 4900 KB Output is correct
34 Correct 17 ms 2636 KB Output is correct
35 Correct 127 ms 9976 KB Output is correct
36 Correct 114 ms 9924 KB Output is correct
37 Correct 126 ms 9932 KB Output is correct
38 Correct 130 ms 9992 KB Output is correct
39 Correct 71 ms 9856 KB Output is correct
40 Correct 127 ms 9984 KB Output is correct
41 Correct 133 ms 9948 KB Output is correct
42 Correct 83 ms 9916 KB Output is correct
43 Correct 46 ms 10120 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 47 ms 5528 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 4 ms 1044 KB Output is correct
58 Correct 16 ms 1744 KB Output is correct
59 Correct 126 ms 11144 KB Output is correct
60 Correct 125 ms 11064 KB Output is correct
61 Correct 119 ms 11064 KB Output is correct
62 Correct 111 ms 11068 KB Output is correct
63 Correct 75 ms 11044 KB Output is correct
64 Correct 132 ms 11104 KB Output is correct
65 Correct 141 ms 11160 KB Output is correct
66 Correct 91 ms 11056 KB Output is correct
67 Correct 60 ms 11376 KB Output is correct