답안 #567063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567063 2022-05-23T07:45:19 Z tqbfjotld Sightseeing in Kyoto (JOI22_kyoto) C++14
40 / 100
2000 ms 214180 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int INF = 999999999999999999LL;

int arr1[100005];
int arr2[100005];

struct node{
    int s,e;
    pair<int,int> v;
    node *l,*r;
    node (int _s, int _e, bool arr, bool lr){
        s = _s; e = _e;
        if (s==e){
            v = make_pair((arr?arr1:arr2)[s],lr?s:-s);
        }
        if (s!=e){
            l = new node(s,(s+e)/2,arr,lr);
            r = new node((s+e)/2+1,e,arr,lr);
            v = min(l->v,r->v);
        }
    }
    pair<int,int> qu(int a, int b){
        if (a<=s && e<=b){
            return v;
        }
        if (b<=(s+e)/2){
            return l->qu(a,b);
        }
        if (a>(s+e)/2){
            return r->qu(a,b);
        }
        return min(l->qu(a,b),r->qu(a,b));
    }
}*r1,*r2,*r3,*r4;

map<pair<int,int>,int> m1,m2;

set<int> s1,s2;

int recl(int a, int b){
    //printf("call recl %lld %lld\n",a,b);
    if (a==0) return arr1[0]*b;
    if (b==0) return arr2[0]*a;
    if (m1.count({a,b})) return m1[{a,b}];
    auto opt1 = r1->qu(0,a-1);
    auto opt2 = r2->qu(0,b-1);
    return m1[{a,b}] = min(recl(opt1.second,b)+arr2[b]*(a-opt1.second),recl(a,opt2.second)+arr1[a]*(b-opt2.second));
}

int n,m;

int recr(int a, int b){
    //printf("call recr %lld %lld\n",a,b);
    if (a==n-1) return arr1[n-1]*(m-1-b);
    if (b==m-1) return arr2[m-1]*(n-1-a);
    if (m2.count({a,b})) return m2[{a,b}];
    auto opt1 = r3->qu(a+1,n-1);
    auto opt2 = r4->qu(b+1,m-1);
    return m2[{a,b}] = min(recr(-opt1.second,b)+arr2[b]*(-opt1.second-a),recr(a,-opt2.second)+arr1[a]*(-opt2.second-b));
}

 main(){

    scanf("%lld%lld",&n,&m);
    for (int x = 0; x<n; x++){
        scanf("%lld",&arr1[x]);
    }
    for (int x = 0; x<m; x++){
        scanf("%lld",&arr2[x]);
    }
    r1 = new node(0,n-1,true,true);
    r2 = new node(0,m-1,false,true);
    r3 = new node(0,n-1,true,false);
    r4 = new node(0,m-1,false,false);
    auto i1 = r1->qu(0,n-1);
    auto i2 = r2->qu(0,m-1);
    auto i3 = r3->qu(0,n-1);
    auto i4 = r4->qu(0,m-1);
    int tt = i1.first*(-i4.second-i2.second)+i2.first*(-i3.second-i1.second);
    int ans = recl(i1.second,i2.second)+recr(-i3.second,-i4.second)+tt;
    printf("%lld",ans);
}

Compilation message

kyoto.cpp:65:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 |  main(){
      |  ^~~~
kyoto.cpp: In function 'int main()':
kyoto.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
kyoto.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%lld",&arr1[x]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%lld",&arr2[x]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 213 ms 23164 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 253 ms 29024 KB Output is correct
17 Correct 1 ms 724 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 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 88 ms 11412 KB Output is correct
4 Correct 38 ms 22692 KB Output is correct
5 Correct 87 ms 27724 KB Output is correct
6 Correct 11 ms 8780 KB Output is correct
7 Correct 55 ms 51960 KB Output is correct
8 Correct 52 ms 51984 KB Output is correct
9 Correct 82 ms 55588 KB Output is correct
10 Correct 87 ms 54984 KB Output is correct
11 Correct 1536 ms 177232 KB Output is correct
12 Correct 96 ms 56780 KB Output is correct
13 Correct 100 ms 56792 KB Output is correct
14 Correct 1544 ms 175396 KB Output is correct
15 Correct 53 ms 51996 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 212 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 213 ms 23164 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 253 ms 29024 KB Output is correct
17 Correct 1 ms 724 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 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 88 ms 11412 KB Output is correct
32 Correct 38 ms 22692 KB Output is correct
33 Correct 87 ms 27724 KB Output is correct
34 Correct 11 ms 8780 KB Output is correct
35 Correct 55 ms 51960 KB Output is correct
36 Correct 52 ms 51984 KB Output is correct
37 Correct 82 ms 55588 KB Output is correct
38 Correct 87 ms 54984 KB Output is correct
39 Correct 1536 ms 177232 KB Output is correct
40 Correct 96 ms 56780 KB Output is correct
41 Correct 100 ms 56792 KB Output is correct
42 Correct 1544 ms 175396 KB Output is correct
43 Correct 53 ms 51996 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 212 KB Output is correct
50 Correct 1 ms 308 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 304 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 35 ms 23244 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 3 ms 2644 KB Output is correct
58 Correct 14 ms 8112 KB Output is correct
59 Correct 59 ms 52140 KB Output is correct
60 Correct 60 ms 51992 KB Output is correct
61 Correct 107 ms 57080 KB Output is correct
62 Correct 106 ms 57728 KB Output is correct
63 Execution timed out 2086 ms 214180 KB Time limit exceeded
64 Halted 0 ms 0 KB -