Submission #18063

# Submission time Handle Problem Language Result Execution time Memory
18063 2016-01-19T12:51:37 Z tncks0121 즐거운 채소 기르기 (JOI14_growing) C++14
0 / 100
81 ms 8256 KB
#define _CRT_SECURE_NO_WARNINGS
       
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int N_ = 300500;

int N, D[N_];
map<int, int> ren;

ll tb1[N_], tb2[N_];

int tree[N_];
void upd (int x, int d) {
    for(; x > 0 && x <= N+10; x += x & -x) tree[x] += d;
}
int get (int x) {
    int ret = 0;
    for(; x > 0; x -= x & -x) ret += tree[x];
    return ret;
}

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) {
        scanf("%d", &D[i]);
        ren[D[i]] = -1;
    }
    int mx = max_element(D+1, D+N+1) - D;
    --N;
    for(int i = mx; i <= N; i++) D[i] = D[i+1];
    D[N+1] = 0;
    --mx;

    {
        int v = 0;    
        for(auto &it : ren) it.second = ++v;
        for(int i = 1; i <= N; i++) D[i] = ren[D[i]];
    }

    {
        memset(tree, 0, sizeof tree);
        for(int i = 1; i <= N; i++) {
            tb1[i] = tb1[i-1] + (i-1) - get(D[i]);
            upd(D[i], +1);
        }

        memset(tree, 0, sizeof tree);
        for(int i = N; i > 0; i--) {
            tb2[i] = tb2[i+1] + (N-i) - get(D[i]);
            upd(D[i], +1);
        }

        ll ans = (ll)1e15;

        for(int i = 1; i <= N; i++) printf("%3d", D[i]);puts("");
        for(int i = 1; i <= N; i++) printf("%3lld", tb1[i]);puts("");
        for(int i = 1; i <= N; i++) printf("%3lld", tb2[i]);puts("");
        for(int i = 1; i <= N; i++) printf("%3d", abs(mx-i));puts("");
        for(int i = 0; i <= N; i++) {
            ll val = tb1[i] + tb2[i+1] + abs(mx - i);
            printf("%lld ", val);
            ans = min(ans, val);
        }
        printf("%lld\n", ans);
    }


    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 8256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 8256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 8256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 8256 KB Output isn't correct
2 Halted 0 ms 0 KB -