답안 #50378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50378 2018-06-10T21:26:42 Z duality Gap (APIO16_gap) C++11
100 / 100
81 ms 3064 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 ----------
#include "gap.h"

long long findGap(int T,int N) {
    if (T == 1) {
        int i;
        LLI mn = 0,mx = (LLI) (1e18+EPS);
        vlli a,b;
        for (i = 0; i < (N+1)/2; i++) {
            MinMax(mn,mx,&mn,&mx);
            a.pb(mn);
            if (mn != mx) b.pb(mx);
            mn++,mx--;
        }
        for (i = b.size()-1; i >= 0; i--) a.pb(b[i]);
        LLI ans = 0;
        for (i = 1; i < a.size(); i++) ans = max(ans,a[i]-a[i-1]);
        return ans;
    }
    else {
        int i;
        LLI l,r,mn,mx;
        MinMax(0,(LLI) (1e18+EPS),&l,&r);
        LLI a = (r-l-1)/N,b = (r-l-1) % N;
        vlli v;
        v.pb(l);
        for (i = 0; i < N; i++) {
            if (i < b) MinMax(l+i*(a+1)+1,l+(i+1)*(a+1),&mn,&mx);
            else MinMax(l+i*a+b+1,l+(i+1)*a+b,&mn,&mx);
            if (mn != -1) v.pb(mn);
            if (mn != mx) v.pb(mx);
        }
        v.pb(r);
        LLI ans = 0;
        for (i = 1; i < v.size(); i++) ans = max(ans,v[i]-v[i-1]);
        return ans;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:72:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 1; i < a.size(); i++) ans = max(ans,a[i]-a[i-1]);
                     ~~^~~~~~~~~~
gap.cpp:90:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 1; i < v.size(); i++) ans = max(ans,v[i]-v[i-1]);
                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 3 ms 608 KB Output is correct
13 Correct 3 ms 608 KB Output is correct
14 Correct 3 ms 608 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 17 ms 1160 KB Output is correct
17 Correct 15 ms 1160 KB Output is correct
18 Correct 15 ms 1204 KB Output is correct
19 Correct 15 ms 1236 KB Output is correct
20 Correct 13 ms 1236 KB Output is correct
21 Correct 56 ms 3064 KB Output is correct
22 Correct 57 ms 3064 KB Output is correct
23 Correct 57 ms 3064 KB Output is correct
24 Correct 64 ms 3064 KB Output is correct
25 Correct 49 ms 3064 KB Output is correct
26 Correct 60 ms 3064 KB Output is correct
27 Correct 61 ms 3064 KB Output is correct
28 Correct 57 ms 3064 KB Output is correct
29 Correct 56 ms 3064 KB Output is correct
30 Correct 42 ms 3064 KB Output is correct
31 Correct 2 ms 3064 KB Output is correct
32 Correct 2 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3064 KB Output is correct
2 Correct 2 ms 3064 KB Output is correct
3 Correct 2 ms 3064 KB Output is correct
4 Correct 2 ms 3064 KB Output is correct
5 Correct 2 ms 3064 KB Output is correct
6 Correct 2 ms 3064 KB Output is correct
7 Correct 2 ms 3064 KB Output is correct
8 Correct 2 ms 3064 KB Output is correct
9 Correct 2 ms 3064 KB Output is correct
10 Correct 2 ms 3064 KB Output is correct
11 Correct 3 ms 3064 KB Output is correct
12 Correct 3 ms 3064 KB Output is correct
13 Correct 3 ms 3064 KB Output is correct
14 Correct 3 ms 3064 KB Output is correct
15 Correct 3 ms 3064 KB Output is correct
16 Correct 20 ms 3064 KB Output is correct
17 Correct 20 ms 3064 KB Output is correct
18 Correct 20 ms 3064 KB Output is correct
19 Correct 19 ms 3064 KB Output is correct
20 Correct 10 ms 3064 KB Output is correct
21 Correct 81 ms 3064 KB Output is correct
22 Correct 75 ms 3064 KB Output is correct
23 Correct 75 ms 3064 KB Output is correct
24 Correct 76 ms 3064 KB Output is correct
25 Correct 70 ms 3064 KB Output is correct
26 Correct 75 ms 3064 KB Output is correct
27 Correct 75 ms 3064 KB Output is correct
28 Correct 76 ms 3064 KB Output is correct
29 Correct 76 ms 3064 KB Output is correct
30 Correct 43 ms 3064 KB Output is correct
31 Correct 3 ms 3064 KB Output is correct
32 Correct 2 ms 3064 KB Output is correct