답안 #389495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389495 2021-04-14T06:47:35 Z 2qbingxuan Permutation Recovery (info1cup17_permutation) C++14
0 / 100
4 ms 3792 KB
// #define _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
using namespace std;
using ll = int64_t;
const int maxn = 70025;

struct BigInteger : vector<int> {
    static constexpr int base = 1000000000;
    static constexpr int width = 9;
    BigInteger() {}
    explicit BigInteger(int x) : vector<int>{x} {}
    friend istream & operator>>(istream &I, BigInteger &n) {
        string s;
        I >> s;
        n.reserve(s.size() / 9);
        reverse(s.begin(), s.end());
        int cur = 0, cnt = 0;
        for (char c: s) {
            cur = cur * 10 + (c - '0');
            if (++cnt == width) {
                n.emplace_back(cur);
                cur = 0;
                cnt = 0;
            }
        }
        if (cnt)
            n.emplace_back(cur);
        return I;
    }
    BigInteger& operator+=(const BigInteger &rhs) {
        if (size() < rhs.size()) resize(rhs.size());
        int carry = 0;
        for (size_t i = 0; i < rhs.size(); i++) {
            carry += rhs[i] + at(i);
            at(i) = carry % base;
            carry /= base;
        }
        return *this;
    }
    BigInteger& operator-=(const BigInteger &rhs) {
        int carry = 0;
        for (size_t i = 0; i < size(); i++) {
            at(i) -= (i < rhs.size() ? rhs[i] : 0) + carry;
            if (at(i) < 0) {
                at(i) += base;
                carry = 1;
            } else {
                carry = 0;
            }
        }
        while (!empty() && back() == 0) pop_back();
        return *this;
    }
};

BigInteger q[maxn];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> q[i];
    for (int i = n-1; i >= 1; i--)
        q[i] -= q[i-1];

    vector<int> ans{0};
    for (int i = 1; i < n; i++) {
        if (q[i] == static_cast<BigInteger>(1)) {
            ans.insert(ans.begin(), i);
            continue;
        }
        BigInteger sum = static_cast<BigInteger>(1);
        for (int j = 0; j < i; j++) {
            sum += q[ans[j]];
            if (sum == q[i]) {
                ans.insert(ans.begin() + j + 1, i);
                break;
            }
        }
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        p[ans[i]] = i+1;
    for (int i = 0; i < n; i++)
        cout << p[i] << (i+1==n ? '\n' : ' ');
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 3792 KB Execution killed with signal 11