Submission #270145

# Submission time Handle Problem Language Result Execution time Memory
270145 2020-08-17T12:42:49 Z egekabas Permutation Recovery (info1cup17_permutation) C++14
25 / 100
4000 ms 384 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 unsigned long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
vector<ll> g[409];
ll a[409];
ll n;
ll beg = 0;
ll fr[409];
ll ans[409];
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];
    for(ll i = 1; i <= n; ++i){
        if(a[i] == 1){
            fr[i] = beg;
            beg = i;
            continue;
        }
        ll cur = 0;
        ll idx = beg;
        while(1){
            cur += a[idx];
            if(fr[idx] == 0 || cur == a[i]-1){
                fr[i] = fr[idx];
                fr[idx] = i;
                break;
            }
            idx = fr[idx];
        }
    }
    ll idx = beg;
    ll cnt = 1;
    while(idx){
        ans[idx] = cnt++;
        idx = fr[idx];
    }
    for(ll i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Execution timed out 4077 ms 384 KB Time limit exceeded
4 Halted 0 ms 0 KB -