답안 #399477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399477 2021-05-05T21:34:01 Z duality Cultivation (JOI17_cultivation) C++11
60 / 100
2000 ms 332 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int S[300],E[300];
int main() {
    int i;
    int R,C,N;
    scanf("%d %d %d",&R,&C,&N);
    for (i = 0; i < N; i++) scanf("%d %d",&S[i],&E[i]),S[i]--,E[i]--;

    int j,k,l,m,n;
    LLI ans = 1e10;
    if (R <= 40) {
        for (int u = 0; u < R; u++) {
            for (int d = 0; d < R; d++) {
                vector<pair<int,pii> > vv;
                for (i = 0; i < N; i++) {
                    vv.pb(mp(max(S[i]-u,0),mp(-1,E[i])));
                    vv.pb(mp(min(S[i]+d+1,R),mp(1,E[i])));
                }
                int l = 0,r = 0,lr = 0;
                multiset<int> SS;
                sort(vv.begin(),vv.end());
                for (i = 0; i < vv.size(); i++) {
                    if (vv[i].second.first == -1) SS.insert(vv[i].second.second);
                    else SS.erase(SS.find(vv[i].second.second));
                    if ((i < vv.size()-1) && (vv[i].first < vv[i+1].first)) {
                        if (SS.empty()) l = 2e9;
                        else {
                            l = max(l,*SS.begin());
                            r = max(r,C-*SS.rbegin()-1);
                            for (auto it = SS.begin(); it != SS.end(); it++) {
                                auto it2 = it;
                                it2++;
                                if (it2 != SS.end()) lr = max(lr,*it2-*it-1);
                            }
                        }
                    }
                }
                if (vv[0].first != 0) l = 2e9;
                if (vv.back().first != R) l = 2e9;
                if (lr > (LLI) l+r) r += lr-l-r;
                ans = min(ans,(LLI) u+d+l+r);
            }
        }
    }
    else {
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) {
                int r = C-E[i]-1,u = S[j];
                vi dd;
                for (k = 0; k < N; k++) {
                    for (l = 0; l < N; l++) dd.pb(max(S[k]-S[l]-u-1,0));
                    dd.pb(R-S[k]-1);
                }
                dd.pb(0);
                dd.resize(unique(dd.begin(),dd.end())-dd.begin());
                for (k = 0; k < dd.size(); k++) {
                    int d = dd[k];
                    int L = 0;
                    vi poss;
                    vector<pair<int,pair<int,pii> > > vv;
                    poss.pb(0),poss.pb(C);
                    for (m = 0; m < N; m++) {
                        poss.pb(E[m]),poss.pb(min(E[m]+r+1,C));
                        vv.pb(mp(max(S[m]-u,0),mp(-1,mp(E[m],min(E[m]+r+1,C)))));
                        vv.pb(mp(min(S[m]+d+1,R),mp(1,mp(E[m],min(E[m]+r+1,C)))));
                    }
                    sort(poss.begin(),poss.end());
                    poss.resize(unique(poss.begin(),poss.end())-poss.begin());
                    int temp[100];
                    fill(temp,temp+poss.size(),0);
                    sort(vv.begin(),vv.end());
                    for (m = 0; m < vv.size(); m++) {
                        int s = lower_bound(poss.begin(),poss.end(),vv[m].second.second.first)-poss.begin();
                        int e = lower_bound(poss.begin(),poss.end(),vv[m].second.second.second)-poss.begin();
                        for (n = s; n < e; n++) temp[n] -= vv[m].second.first;
                        if ((m < vv.size()-1) && (vv[m].first < vv[m+1].first)) {
                            int last = 2e9;
                            for (n = poss.size()-2; n >= 0; n--) {
                                if (temp[n] > 0) last = poss[n];
                                else L = max(L,last-poss[n]);
                            }
                        }
                    }
                    if (vv[0].first != 0) L = 2e9;
                    if (vv.back().first != R) L = 2e9;
                    ans = min(ans,(LLI) r+u+L+d);
                }
            }
        }
    }
    printf("%lld\n",ans);

    return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:78:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |                 for (i = 0; i < vv.size(); i++) {
      |                             ~~^~~~~~~~~~~
cultivation.cpp:81:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                     if ((i < vv.size()-1) && (vv[i].first < vv[i+1].first)) {
      |                          ~~^~~~~~~~~~~~~
cultivation.cpp:112:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |                 for (k = 0; k < dd.size(); k++) {
      |                             ~~^~~~~~~~~~~
cultivation.cpp:128:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, std::pair<int, int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |                     for (m = 0; m < vv.size(); m++) {
      |                                 ~~^~~~~~~~~~~
cultivation.cpp:132:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, std::pair<int, int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |                         if ((m < vv.size()-1) && (vv[m].first < vv[m+1].first)) {
      |                              ~~^~~~~~~~~~~~~
cultivation.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |     scanf("%d %d %d",&R,&C,&N);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:63:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     for (i = 0; i < N; i++) scanf("%d %d",&S[i],&E[i]),S[i]--,E[i]--;
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 16 ms 304 KB Output is correct
19 Correct 10 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 27 ms 204 KB Output is correct
22 Correct 82 ms 204 KB Output is correct
23 Correct 14 ms 300 KB Output is correct
24 Correct 150 ms 304 KB Output is correct
25 Correct 108 ms 204 KB Output is correct
26 Correct 232 ms 204 KB Output is correct
27 Correct 226 ms 324 KB Output is correct
28 Correct 138 ms 300 KB Output is correct
29 Correct 204 ms 204 KB Output is correct
30 Correct 227 ms 332 KB Output is correct
31 Correct 235 ms 204 KB Output is correct
32 Correct 233 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 16 ms 304 KB Output is correct
19 Correct 10 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 27 ms 204 KB Output is correct
22 Correct 82 ms 204 KB Output is correct
23 Correct 14 ms 300 KB Output is correct
24 Correct 150 ms 304 KB Output is correct
25 Correct 108 ms 204 KB Output is correct
26 Correct 232 ms 204 KB Output is correct
27 Correct 226 ms 324 KB Output is correct
28 Correct 138 ms 300 KB Output is correct
29 Correct 204 ms 204 KB Output is correct
30 Correct 227 ms 332 KB Output is correct
31 Correct 235 ms 204 KB Output is correct
32 Correct 233 ms 312 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 186 ms 308 KB Output is correct
35 Correct 243 ms 332 KB Output is correct
36 Correct 239 ms 324 KB Output is correct
37 Correct 177 ms 324 KB Output is correct
38 Correct 236 ms 324 KB Output is correct
39 Correct 231 ms 312 KB Output is correct
40 Correct 239 ms 312 KB Output is correct
41 Correct 169 ms 312 KB Output is correct
42 Correct 205 ms 312 KB Output is correct
43 Correct 229 ms 204 KB Output is correct
44 Correct 233 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 204 KB Output is correct
2 Correct 746 ms 288 KB Output is correct
3 Correct 873 ms 324 KB Output is correct
4 Correct 833 ms 288 KB Output is correct
5 Correct 796 ms 324 KB Output is correct
6 Correct 793 ms 204 KB Output is correct
7 Correct 178 ms 204 KB Output is correct
8 Correct 543 ms 284 KB Output is correct
9 Correct 920 ms 288 KB Output is correct
10 Correct 789 ms 324 KB Output is correct
11 Correct 886 ms 324 KB Output is correct
12 Correct 847 ms 284 KB Output is correct
13 Correct 275 ms 204 KB Output is correct
14 Correct 828 ms 288 KB Output is correct
15 Correct 182 ms 204 KB Output is correct
16 Correct 1066 ms 288 KB Output is correct
17 Correct 996 ms 328 KB Output is correct
18 Correct 211 ms 204 KB Output is correct
19 Correct 880 ms 296 KB Output is correct
20 Correct 736 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 204 KB Output is correct
2 Correct 746 ms 288 KB Output is correct
3 Correct 873 ms 324 KB Output is correct
4 Correct 833 ms 288 KB Output is correct
5 Correct 796 ms 324 KB Output is correct
6 Correct 793 ms 204 KB Output is correct
7 Correct 178 ms 204 KB Output is correct
8 Correct 543 ms 284 KB Output is correct
9 Correct 920 ms 288 KB Output is correct
10 Correct 789 ms 324 KB Output is correct
11 Correct 886 ms 324 KB Output is correct
12 Correct 847 ms 284 KB Output is correct
13 Correct 275 ms 204 KB Output is correct
14 Correct 828 ms 288 KB Output is correct
15 Correct 182 ms 204 KB Output is correct
16 Correct 1066 ms 288 KB Output is correct
17 Correct 996 ms 328 KB Output is correct
18 Correct 211 ms 204 KB Output is correct
19 Correct 880 ms 296 KB Output is correct
20 Correct 736 ms 204 KB Output is correct
21 Execution timed out 2091 ms 332 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 16 ms 304 KB Output is correct
19 Correct 10 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 27 ms 204 KB Output is correct
22 Correct 82 ms 204 KB Output is correct
23 Correct 14 ms 300 KB Output is correct
24 Correct 150 ms 304 KB Output is correct
25 Correct 108 ms 204 KB Output is correct
26 Correct 232 ms 204 KB Output is correct
27 Correct 226 ms 324 KB Output is correct
28 Correct 138 ms 300 KB Output is correct
29 Correct 204 ms 204 KB Output is correct
30 Correct 227 ms 332 KB Output is correct
31 Correct 235 ms 204 KB Output is correct
32 Correct 233 ms 312 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 186 ms 308 KB Output is correct
35 Correct 243 ms 332 KB Output is correct
36 Correct 239 ms 324 KB Output is correct
37 Correct 177 ms 324 KB Output is correct
38 Correct 236 ms 324 KB Output is correct
39 Correct 231 ms 312 KB Output is correct
40 Correct 239 ms 312 KB Output is correct
41 Correct 169 ms 312 KB Output is correct
42 Correct 205 ms 312 KB Output is correct
43 Correct 229 ms 204 KB Output is correct
44 Correct 233 ms 332 KB Output is correct
45 Correct 111 ms 204 KB Output is correct
46 Correct 746 ms 288 KB Output is correct
47 Correct 873 ms 324 KB Output is correct
48 Correct 833 ms 288 KB Output is correct
49 Correct 796 ms 324 KB Output is correct
50 Correct 793 ms 204 KB Output is correct
51 Correct 178 ms 204 KB Output is correct
52 Correct 543 ms 284 KB Output is correct
53 Correct 920 ms 288 KB Output is correct
54 Correct 789 ms 324 KB Output is correct
55 Correct 886 ms 324 KB Output is correct
56 Correct 847 ms 284 KB Output is correct
57 Correct 275 ms 204 KB Output is correct
58 Correct 828 ms 288 KB Output is correct
59 Correct 182 ms 204 KB Output is correct
60 Correct 1066 ms 288 KB Output is correct
61 Correct 996 ms 328 KB Output is correct
62 Correct 211 ms 204 KB Output is correct
63 Correct 880 ms 296 KB Output is correct
64 Correct 736 ms 204 KB Output is correct
65 Execution timed out 2091 ms 332 KB Time limit exceeded
66 Halted 0 ms 0 KB -