Submission #389479

# Submission time Handle Problem Language Result Execution time Memory
389479 2021-04-14T06:38:10 Z 2qbingxuan Permutation Recovery (info1cup17_permutation) C++14
10 / 100
1 ms 332 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;
    friend istream & operator>>(istream &I, BigInteger &n) {
        string s;
        I >> s;
        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 < rhs.size(); i++) {
            carry = at(i) - rhs[i] - carry;
            if (carry < 0) {
                at(i) = (carry % base + base) % base;
                carry += at(i);
                carry /= base;
            } else {
                at(i) = carry;
            }
            at(i) = carry % base;
            carry /= base;
        }
        return *this;
    }
};

ll q[maxn];
ll here[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];

    here[0] = 1;
    vector<int> ans{0};
    for (int i = 1; i < n; i++) {
        here[i] = q[i] - q[i-1];
        if (here[i] == 1) {
            ans.insert(ans.begin(), i);
            continue;
        }
        int sum = 0;
        for (int j = 0; j < i; j++) {
            debug(j);
            sum += here[ans[j]];
            if (sum + 1 == here[i]) {
                debug(j, ans.size());
                ans.insert(ans.begin() + j + 1, i);
                break;
            }
        }
        safe;
    }
    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' : ' ');
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct