Submission #1605667


Source Code Expand

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef long long int ll;

#define xprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define debugv(v) {printf("L%d %s > ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) {printf("L%d %s > ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;}
#define debugaa(m,h,w) {printf("L%d %s >\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}}
#define ALL(v) (v).begin(),(v).end()
#define repeat(cnt,l) for(auto cnt=0ll;cnt<(l);++cnt)
#define iterate(cnt,b,e) for(auto cnt=(b);cnt!=(e);++cnt)
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
#define EPS 1e-12
template<typename T1, typename T2> ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }
template<typename iterator> inline size_t argmin(iterator begin, iterator end) { return distance(begin, min_element(begin, end)); }
template<typename iterator> inline size_t argmax(iterator begin, iterator end) { return distance(begin, max_element(begin, end)); }
template<typename T> T& maxset(T& to, const T& val) { return to = max(to, val); }
template<typename T> T& minset(T& to, const T& val) { return to = min(to, val); }

mt19937_64 randdev(8901016);
inline ll rand_range(ll l, ll h) {
    return uniform_int_distribution<ll>(l, h)(randdev);
}

#ifdef __MAI
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
#ifdef __VSCC
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
namespace {
#define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E)
    class MaiScanner {
    public:
        template<typename T> void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        inline MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
        inline MaiScanner& operator>>(string& var) {
            int cc = getchar_unlocked();
            for (; !isvisiblechar(cc); cc = getchar_unlocked());
            for (; isvisiblechar(cc); cc = getchar_unlocked())
                var.push_back(cc);
            return *this;
        }
        template<typename IT> void in(IT begin, IT end) {
            for (auto it = begin; it != end; ++it) *this >> *it;
        }
    };
}
MaiScanner scanner;


template<typename T = ll>
class bitree {
public:
    int size;
    vector<T> data;
    bitree(int size) :size(size + 1), data(size + 1) {}

    // -------------------------------------------------------
    // 和に関するBIT
    // 1..rの範囲の値の和を求める.
    T sum(int r) {
        T s = 0;
        while (r) {
            s += data[r];
            r -= r&-r; //  r&-r と書くことで最下のビットを得る
        }
        return s;
    }
    // idxの要素の値をval増やす
    void add(int idx, T val) {
        while (idx <= size) {
            data[idx] += val;
            idx += idx&-idx;
        }
    }
};



ll m, n, kei;

int aa[100010];
int bb[100010];
int bb_cv[100010];

int convert[100010];

int main() {

    scanner >> n;
    if (n == 1) { cout << -1 << endl; return 0; }

    repeat(i, n) {
        int a;
        scanner >> a;
        --a;
        convert[a] = i;
        aa[i] = a;
    }
    bool same = true;
    repeat(i, n) {
        int b;
        scanner >> b;
        --b;
        bb[i] = b;
        bb_cv[i] = convert[b];

        same &= aa[i] == bb[i];
    }

    if (same) {
        swap(aa[0], aa[1]);
        iterate(it, aa, aa + n) {
            printf("%d ", *it);
        }
        cout << endl;
        return 0;
    }

    ll inv = 0; // 転置数
    bitree<ll> bit(n);

    repeat(i, n) {
        int b = bb_cv[i];
        inv += bit.sum(n - b);
        bit.add(n - b, 1);
    }

    if (inv % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    inv /= 2;

    repeat(i, n) {
        repeat(j, n-1) {
            if (bb_cv[i] > bb_cv[j]){
                swap(bb_cv[i], bb_cv[j]);
                if (!--inv) goto l_break;
            }
        }
    }
    l_break:;


    iterate(it, bb_cv, bb_cv + n) {
        printf("%d ", aa[*it] + 1);
    }
    cout << endl;


    return 0;
}

Submission Info

Submission Time
Task C - 転倒距離
User m_buyoh
Language C++14 (GCC 5.4.1)
Score 0
Code Size 5002 Byte
Status WA
Exec Time 2103 ms
Memory 2560 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 0 / 30 0 / 70
Status
AC × 1
WA × 2
AC × 11
WA × 11
AC × 20
WA × 12
TLE × 9
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt
Subtask2 sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt
Case Name Status Exec Time Memory
sample_01.txt WA 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt WA 1 ms 256 KB
subtask1_01.txt AC 1 ms 384 KB
subtask1_02.txt WA 6 ms 384 KB
subtask1_03.txt WA 2 ms 256 KB
subtask1_04.txt WA 2 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt WA 2 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt WA 4 ms 384 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt WA 5 ms 384 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 384 KB
subtask1_15.txt AC 1 ms 384 KB
subtask1_16.txt WA 6 ms 384 KB
subtask1_17.txt AC 1 ms 384 KB
subtask1_18.txt WA 6 ms 384 KB
subtask1_19.txt WA 6 ms 384 KB
subtask2_01.txt AC 2 ms 640 KB
subtask2_02.txt TLE 2103 ms 2048 KB
subtask2_03.txt TLE 2103 ms 2432 KB
subtask2_04.txt AC 5 ms 1536 KB
subtask2_05.txt AC 7 ms 2048 KB
subtask2_06.txt AC 4 ms 1280 KB
subtask2_07.txt AC 7 ms 2176 KB
subtask2_08.txt TLE 2103 ms 2432 KB
subtask2_09.txt AC 5 ms 1536 KB
subtask2_10.txt AC 5 ms 1408 KB
subtask2_11.txt WA 902 ms 1536 KB
subtask2_12.txt AC 9 ms 2560 KB
subtask2_13.txt TLE 2103 ms 2560 KB
subtask2_14.txt AC 8 ms 2304 KB
subtask2_15.txt TLE 2103 ms 2560 KB
subtask2_16.txt TLE 2103 ms 2560 KB
subtask2_17.txt TLE 2103 ms 2560 KB
subtask2_18.txt TLE 2103 ms 2560 KB
subtask2_19.txt TLE 2103 ms 2560 KB