Submission #399902

# Submission time Handle Problem Language Result Execution time Memory
399902 2021-05-06T21:44:38 Z duality Cultivation (JOI17_cultivation) C++11
30 / 100
1504 ms 262148 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));
        for (j = 0; j < R; j++) vv.pb(j);
        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(R,l),0)),vv2.pb(mp(mp(R,r),1)),vv2.pb(mp(mp(R,lr),2));
            for (k = v.size()-1; k >= 0; k--) {
                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);
                vv2.pb(mp(mp(v[k].first-1,l),0)),vv2.pb(mp(mp(v[k].first-1,r),1)),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--) {
            if (vv2[j].first.first < R) ans = min(ans,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:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (j = 0; j < vv.size(); j++) {
      |                     ~~^~~~~~~~~~~
cultivation.cpp:84: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]
   84 |             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 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 300 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 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 300 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 3 ms 204 KB Output is correct
18 Correct 39 ms 460 KB Output is correct
19 Correct 10 ms 392 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 34 ms 468 KB Output is correct
22 Correct 204 ms 552 KB Output is correct
23 Correct 16 ms 396 KB Output is correct
24 Correct 617 ms 796 KB Output is correct
25 Correct 343 ms 788 KB Output is correct
26 Correct 1458 ms 1204 KB Output is correct
27 Correct 1391 ms 1228 KB Output is correct
28 Correct 616 ms 792 KB Output is correct
29 Correct 1316 ms 1232 KB Output is correct
30 Correct 1384 ms 1100 KB Output is correct
31 Correct 1418 ms 1232 KB Output is correct
32 Correct 1416 ms 1232 KB Output is correct
# Verdict Execution time Memory 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 300 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 3 ms 204 KB Output is correct
18 Correct 39 ms 460 KB Output is correct
19 Correct 10 ms 392 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 34 ms 468 KB Output is correct
22 Correct 204 ms 552 KB Output is correct
23 Correct 16 ms 396 KB Output is correct
24 Correct 617 ms 796 KB Output is correct
25 Correct 343 ms 788 KB Output is correct
26 Correct 1458 ms 1204 KB Output is correct
27 Correct 1391 ms 1228 KB Output is correct
28 Correct 616 ms 792 KB Output is correct
29 Correct 1316 ms 1232 KB Output is correct
30 Correct 1384 ms 1100 KB Output is correct
31 Correct 1418 ms 1232 KB Output is correct
32 Correct 1416 ms 1232 KB Output is correct
33 Correct 57 ms 296 KB Output is correct
34 Correct 1340 ms 1216 KB Output is correct
35 Correct 1428 ms 1236 KB Output is correct
36 Correct 1411 ms 1232 KB Output is correct
37 Correct 1251 ms 788 KB Output is correct
38 Correct 1493 ms 1104 KB Output is correct
39 Correct 1452 ms 1236 KB Output is correct
40 Correct 1451 ms 1236 KB Output is correct
41 Correct 1108 ms 1236 KB Output is correct
42 Correct 1295 ms 1228 KB Output is correct
43 Correct 1362 ms 1212 KB Output is correct
44 Correct 1504 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 285 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 285 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 300 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 3 ms 204 KB Output is correct
18 Correct 39 ms 460 KB Output is correct
19 Correct 10 ms 392 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 34 ms 468 KB Output is correct
22 Correct 204 ms 552 KB Output is correct
23 Correct 16 ms 396 KB Output is correct
24 Correct 617 ms 796 KB Output is correct
25 Correct 343 ms 788 KB Output is correct
26 Correct 1458 ms 1204 KB Output is correct
27 Correct 1391 ms 1228 KB Output is correct
28 Correct 616 ms 792 KB Output is correct
29 Correct 1316 ms 1232 KB Output is correct
30 Correct 1384 ms 1100 KB Output is correct
31 Correct 1418 ms 1232 KB Output is correct
32 Correct 1416 ms 1232 KB Output is correct
33 Correct 57 ms 296 KB Output is correct
34 Correct 1340 ms 1216 KB Output is correct
35 Correct 1428 ms 1236 KB Output is correct
36 Correct 1411 ms 1232 KB Output is correct
37 Correct 1251 ms 788 KB Output is correct
38 Correct 1493 ms 1104 KB Output is correct
39 Correct 1452 ms 1236 KB Output is correct
40 Correct 1451 ms 1236 KB Output is correct
41 Correct 1108 ms 1236 KB Output is correct
42 Correct 1295 ms 1228 KB Output is correct
43 Correct 1362 ms 1212 KB Output is correct
44 Correct 1504 ms 1104 KB Output is correct
45 Runtime error 285 ms 262148 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -