Submission #399904

# Submission time Handle Problem Language Result Execution time Memory
399904 2021-05-06T21:48:08 Z duality Cultivation (JOI17_cultivation) C++11
80 / 100
2000 ms 792 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];
vi vv;
vector<pair<pii,int> > vv2;
multiset<int> SS;
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;
    LLI ans = 2e9;
    for (i = 0; i < N; i++) {
        int u = S[i];
        vv.pb(0),vv.pb(R-1);
        for (j = 0; j < N; j++) vv.pb(max(S[j]-u-1,0));
        sort(vv.begin(),vv.end());
        vv.resize(unique(vv.begin(),vv.end())-vv.begin());
        for (j = 0; j < vv.size(); j++) {
            vpii v;
            for (k = 0; k < N; k++) {
                if ((vv[j] >= S[k]-u) && (vv[j] <= S[k])) v.pb(mp(0,E[k]));
                else if (vv[j] > S[k]) v.pb(mp(vv[j]-S[k],E[k]));
            }
            sort(v.begin(),v.end());
            for (k = 0; k < v.size(); k++) SS.insert(v[k].second);
            int l = *SS.begin(),r = C-*SS.rbegin()-1,lr = 0;
            for (auto it = SS.begin(); it != SS.end(); it++) {
                auto it2 = it;
                it2++;
                if (it2 != SS.end()) lr = max(lr,*it2-*it-1);
            }
            vv2.pb(mp(mp(2e9,l),0)),vv2.pb(mp(mp(2e9,r),1)),vv2.pb(mp(mp(2e9,lr),2));
            for (k = v.size()-1; k >= 0; k--) {
                int ll = l,rr = r,lr2 = lr;
                auto it = SS.find(v[k].second);
                it = SS.erase(it);
                auto it2 = it;
                if ((it2 != SS.begin()) && (it != SS.end())) lr = max(lr,*it-*(--it2)-1);
                if (!SS.empty()) l = max(l,*SS.begin()),r = max(r,C-*SS.rbegin()-1);
                else l = max(l,(int) 2e9);
                if (l != ll) vv2.pb(mp(mp(v[k].first-1,l),0));
                if (r != rr) vv2.pb(mp(mp(v[k].first-1,r),1));
                if (lr != lr2) vv2.pb(mp(mp(v[k].first-1,lr),2));
            }
        }
        int l = 0,r = 0,lr = 0;
        sort(vv2.begin(),vv2.end());
        for (j = vv2.size()-1; j >= 0; j--) {
            ans = min(ans,(LLI) u+vv2[j].first.first+1+max((LLI) l+r,(LLI) lr));
            if (vv2[j].second == 0) l = max(l,vv2[j].first.second);
            else if (vv2[j].second == 1) r = max(r,vv2[j].first.second);
            else lr = max(lr,vv2[j].first.second);
        }
        vv.clear(),vv2.clear();
    }
    printf("%lld\n",ans);

    return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:76:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (j = 0; j < vv.size(); j++) {
      |                     ~~^~~~~~~~~~~
cultivation.cpp:83:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |             for (k = 0; k < v.size(); k++) SS.insert(v[k].second);
      |                         ~~^~~~~~~~~~
cultivation.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |     scanf("%d %d %d",&R,&C,&N);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:66:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |     for (i = 0; i < N; i++) scanf("%d %d",&S[i],&E[i]),S[i]--,E[i]--;
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 296 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 296 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 1 ms 204 KB Output is correct
18 Correct 10 ms 316 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 8 ms 204 KB Output is correct
22 Correct 54 ms 332 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 162 ms 332 KB Output is correct
25 Correct 92 ms 204 KB Output is correct
26 Correct 423 ms 336 KB Output is correct
27 Correct 407 ms 452 KB Output is correct
28 Correct 211 ms 312 KB Output is correct
29 Correct 380 ms 332 KB Output is correct
30 Correct 298 ms 332 KB Output is correct
31 Correct 427 ms 344 KB Output is correct
32 Correct 386 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 296 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 1 ms 204 KB Output is correct
18 Correct 10 ms 316 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 8 ms 204 KB Output is correct
22 Correct 54 ms 332 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 162 ms 332 KB Output is correct
25 Correct 92 ms 204 KB Output is correct
26 Correct 423 ms 336 KB Output is correct
27 Correct 407 ms 452 KB Output is correct
28 Correct 211 ms 312 KB Output is correct
29 Correct 380 ms 332 KB Output is correct
30 Correct 298 ms 332 KB Output is correct
31 Correct 427 ms 344 KB Output is correct
32 Correct 386 ms 452 KB Output is correct
33 Correct 42 ms 204 KB Output is correct
34 Correct 380 ms 392 KB Output is correct
35 Correct 378 ms 332 KB Output is correct
36 Correct 354 ms 384 KB Output is correct
37 Correct 340 ms 376 KB Output is correct
38 Correct 403 ms 392 KB Output is correct
39 Correct 385 ms 372 KB Output is correct
40 Correct 428 ms 396 KB Output is correct
41 Correct 176 ms 204 KB Output is correct
42 Correct 265 ms 332 KB Output is correct
43 Correct 362 ms 332 KB Output is correct
44 Correct 431 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 3 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 308 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 3 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 308 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 76 ms 332 KB Output is correct
22 Correct 85 ms 332 KB Output is correct
23 Correct 82 ms 452 KB Output is correct
24 Correct 77 ms 460 KB Output is correct
25 Correct 85 ms 380 KB Output is correct
26 Correct 50 ms 304 KB Output is correct
27 Correct 84 ms 432 KB Output is correct
28 Correct 84 ms 368 KB Output is correct
29 Correct 84 ms 332 KB Output is correct
30 Correct 86 ms 372 KB Output is correct
31 Correct 86 ms 372 KB Output is correct
32 Correct 80 ms 460 KB Output is correct
33 Correct 75 ms 436 KB Output is correct
34 Correct 99 ms 332 KB Output is correct
35 Correct 82 ms 364 KB Output is correct
36 Correct 80 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 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 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 296 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 1 ms 204 KB Output is correct
18 Correct 10 ms 316 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 8 ms 204 KB Output is correct
22 Correct 54 ms 332 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 162 ms 332 KB Output is correct
25 Correct 92 ms 204 KB Output is correct
26 Correct 423 ms 336 KB Output is correct
27 Correct 407 ms 452 KB Output is correct
28 Correct 211 ms 312 KB Output is correct
29 Correct 380 ms 332 KB Output is correct
30 Correct 298 ms 332 KB Output is correct
31 Correct 427 ms 344 KB Output is correct
32 Correct 386 ms 452 KB Output is correct
33 Correct 42 ms 204 KB Output is correct
34 Correct 380 ms 392 KB Output is correct
35 Correct 378 ms 332 KB Output is correct
36 Correct 354 ms 384 KB Output is correct
37 Correct 340 ms 376 KB Output is correct
38 Correct 403 ms 392 KB Output is correct
39 Correct 385 ms 372 KB Output is correct
40 Correct 428 ms 396 KB Output is correct
41 Correct 176 ms 204 KB Output is correct
42 Correct 265 ms 332 KB Output is correct
43 Correct 362 ms 332 KB Output is correct
44 Correct 431 ms 332 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 2 ms 204 KB Output is correct
47 Correct 2 ms 204 KB Output is correct
48 Correct 2 ms 204 KB Output is correct
49 Correct 2 ms 308 KB Output is correct
50 Correct 2 ms 204 KB Output is correct
51 Correct 2 ms 204 KB Output is correct
52 Correct 2 ms 204 KB Output is correct
53 Correct 3 ms 204 KB Output is correct
54 Correct 2 ms 204 KB Output is correct
55 Correct 2 ms 204 KB Output is correct
56 Correct 2 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 2 ms 204 KB Output is correct
59 Correct 2 ms 308 KB Output is correct
60 Correct 2 ms 208 KB Output is correct
61 Correct 2 ms 204 KB Output is correct
62 Correct 2 ms 204 KB Output is correct
63 Correct 2 ms 304 KB Output is correct
64 Correct 2 ms 204 KB Output is correct
65 Correct 76 ms 332 KB Output is correct
66 Correct 85 ms 332 KB Output is correct
67 Correct 82 ms 452 KB Output is correct
68 Correct 77 ms 460 KB Output is correct
69 Correct 85 ms 380 KB Output is correct
70 Correct 50 ms 304 KB Output is correct
71 Correct 84 ms 432 KB Output is correct
72 Correct 84 ms 368 KB Output is correct
73 Correct 84 ms 332 KB Output is correct
74 Correct 86 ms 372 KB Output is correct
75 Correct 86 ms 372 KB Output is correct
76 Correct 80 ms 460 KB Output is correct
77 Correct 75 ms 436 KB Output is correct
78 Correct 99 ms 332 KB Output is correct
79 Correct 82 ms 364 KB Output is correct
80 Correct 80 ms 432 KB Output is correct
81 Correct 1055 ms 556 KB Output is correct
82 Correct 1016 ms 588 KB Output is correct
83 Correct 1475 ms 784 KB Output is correct
84 Correct 1439 ms 784 KB Output is correct
85 Execution timed out 2081 ms 792 KB Time limit exceeded
86 Halted 0 ms 0 KB -