답안 #399452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399452 2021-05-05T20:31:20 Z duality Cultivation (JOI17_cultivation) C++11
0 / 100
226 ms 208 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;
    int t;
    LLI ans = 1e10;
    for (t = 0; t < 4; t++) {
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) {
                int r = C-E[i]-1,u = S[i];
                set<int> SS;
                for (k = 0; k < N; k++) {
                    for (l = 0; l < N; l++) {
                        int d = max(S[k]-S[l]-u-1,0);
                        if (SS.count(d)) continue;
                        else SS.insert(d);
                        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]);
                                }
                            }
                        }
                        ans = min(ans,(LLI) r+u+((L == 0) ? 0:r+L)+((d == 0) ? 0:d+u));
                    }
                }
            }
        }

        for (i = 0; i < N; i++) {
            swap(S[i],E[i]);
            S[i] = C-S[i]-1;
        }
        swap(R,C);
    }
    printf("%lld\n",ans);

    return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:92:39: 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]
   92 |                         for (m = 0; m < vv.size(); m++) {
      |                                     ~~^~~~~~~~~~~
cultivation.cpp:96:36: 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]
   96 |                             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 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 226 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 226 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -