Submission #270073

# Submission time Handle Problem Language Result Execution time Memory
270073 2020-08-17T12:20:04 Z egekabas Permutation Recovery (info1cup17_permutation) C++14
10 / 100
5 ms 3968 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
vector<ll> g[70009];
ll a[70009];
bitset<500> bt[70009];
ll n;
ll vis[70009];
vector<ll> ord;
ll ans[70009];
void dfs(ll v){
    vis[v] = 1;
    for(auto u : g[v])
        if(vis[u] == 0)
            dfs(u);
    ord.pb(v);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    
    cin >> n;
    for(ll i = 1; i <= n; ++i)
        cin >> a[i];
    for(ll i = n; i >= 1; --i)
        a[i] -= a[i-1];
    bt[0][0] = 1;
    for(ll i = 1; i <= n; ++i){
        ll cur = a[i]-1;
        for(ll j = i-1; j >= 1; --j){
            if(cur - a[j] >= 0 && bt[j-1][cur-a[j]]){
                g[i].pb(j);
                cur -= a[j];
            }
            else
                g[j].pb(i);
        }
        if(a[i] <= 400)
            bt[i] = bt[i-1]|(bt[i-1]<<a[i]);
    }
    for(ll i = 1; i <= n; ++i)
        if(vis[i] == 0)
            dfs(i);
    for(ll i = 0; i < n; ++i)
        ans[ord[i]] = i+1;
    for(ll i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Runtime error 5 ms 3968 KB Execution killed with signal 11