Submission #568669

# Submission time Handle Problem Language Result Execution time Memory
568669 2022-05-26T03:22:16 Z dantoh000 Sightseeing in Kyoto (JOI22_kyoto) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef pair<double, ii> iii;
const int INF = 1000000000000000000;
int n,m;
int a[1005], b[1005];
set<int> x,y;
priority_queue<iii, vector<iii>, greater<iii> > pq1, pq2;
main(){
    scanf("%lld%lld",&n,&m);
    for (int i = 0; i < n; i++){
        scanf("%lld",&a[i]);
    }
    for (int j = 0; j < m; j++){
        scanf("%lld",&b[j]);
    }
    for (int i = 0; i < n; i++){
        x.insert(i);
    }
    for (int j = 0; j < m; j++){
        y.insert(j);
    }
    for (int i = 0; i < n-1; i++){
        pq1.push({a[i]-a[i+1],{i,i+1}});
    }
    for (int j = 0; j < m-1; j++){
        pq2.push({b[j]-b[j+1],{j,j+1}});
    }
    int ans = 0;
    while (pq1.size() || pq2.size()){
        if (pq2.empty() || (!pq1.empty() && pq1.top().fi < pq2.top().fi)){
            iii cur = pq1.top(); pq1.pop();
            double d = cur.fi;
            int l = cur.se.fi, r = cur.se.se;
            if (x.find(l) == x.end() || x.find(r) == x.end()) continue;
            x.erase(r);
            auto it = x.lower_bound(r);
            if (it == x.end()){
                ///printf("adding H edge %d->%d, length %d and cost %d\n",l,r,r-l,b[*y.rbegin()]);
                ans += b[*y.rbegin()]*(r-l);
            }
            else{
                int nr = *it;
                double nd = (double)(a[l]-a[nr])/(nr-l);
                pq1.push({nd, {l,nr}});
            }
        }
        else {
            iii cur = pq2.top(); pq2.pop();
            double d = cur.fi;
            int l = cur.se.fi, r = cur.se.se;
            if (y.find(l) == y.end() || y.find(r) == y.end()) continue;
            y.erase(r);
            auto it = y.lower_bound(r);
            if (it == y.end()){
                printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
                ans += a[*x.rbegin()]*(r-l);
            }
            else{
                int nr = *it;
                double nd = (double)(b[l]-b[nr])/(nr-l);
                pq2.push({nd, {l,nr}});
            }
        }
    }
    printf("%lld",ans);

}

Compilation message

kyoto.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
kyoto.cpp: In function 'int main()':
kyoto.cpp:37:20: warning: unused variable 'd' [-Wunused-variable]
   37 |             double d = cur.fi;
      |                    ^
kyoto.cpp:60:40: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   60 |                 printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
      |                                       ~^                               ~
      |                                        |                               |
      |                                        int                             long long int
      |                                       %lld
kyoto.cpp:60:44: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   60 |                 printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
      |                                           ~^                             ~
      |                                            |                             |
      |                                            int                           long long int
      |                                           %lld
kyoto.cpp:60:55: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long long int' [-Wformat=]
   60 |                 printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
      |                                                      ~^                    ~~~
      |                                                       |                     |
      |                                                       int                   long long int
      |                                                      %lld
kyoto.cpp:60:67: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long long int' [-Wformat=]
   60 |                 printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
      |                                                                  ~^            ~~~~~~~~~~~~~~
      |                                                                   |                         |
      |                                                                   int                       long long int
      |                                                                  %lld
kyoto.cpp:54:20: warning: unused variable 'd' [-Wunused-variable]
   54 |             double d = cur.fi;
      |                    ^
kyoto.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
kyoto.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
kyoto.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%lld",&b[j]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -