Submission #577478

# Submission time Handle Problem Language Result Execution time Memory
577478 2022-06-14T19:55:41 Z perchuts Gondola (IOI14_gondola) C++17
100 / 100
58 ms 6084 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
 
const int inf = 2e9+1;
const ll mod = 1e9+9;
const int maxn = 1e5+100;
 
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
 
#include "gondola.h"
 
int valid(int n,int v[]){
  vector<ii>v2;
  map<int,bool>mp;
  int mn = inf, idx = -1;
  for(int i=0;i<n;++i){
      if(mp[v[i]]==1)return 0;
      mp[v[i]] = 1;
      if(ckmin(mn,v[i]))idx = i;
  }
  if(mn>=n)return 1;
  for(int i=idx;i<n;++i)if(v[i]<=n)v2.pb({v[i],i-idx});
  for(int i=0;i<idx;++i)if(v[i]<=n)v2.pb({v[i],n-idx+i});
  for(int i=1;i<sz(v2);++i){
    if(v2[i].first-v2[i-1].first!=v2[i].second-v2[i-1].second)return 0;
  }     
  return 1;
}
 
//----------------------
 
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int mn = n+1, idx = 0;
    for(int i=0;i<n;++i){
        if(ckmin(mn,gondolaSeq[i]))idx = i;
    }
    if(mn>n)mn = 1;
    vector<ii>ajusta;
    for(int i=idx;i<n;++i){
        if(gondolaSeq[i]>n)ajusta.pb({gondolaSeq[i],mn});
        mn++;
        if(mn>n)mn = 1;
    }
    for(int i=0;i<idx;++i){
        if(gondolaSeq[i]>n)ajusta.pb({gondolaSeq[i],mn});
        mn++;
        if(mn>n)mn = 1;
    }
    sort(all(ajusta));
    int cur = n+1;
    idx = 0;
    for(auto [b,a]:ajusta){
        while(a!=b){
            replacementSeq[idx++] = a, a = cur++;
        }
    }
    return idx;
}
 
//----------------------
 
ll fastexp(ll b,ll e){
  if(e==0)return 1ll;
  if(e==1)return b;
  ll sqr = fastexp(b,e/2), resp = (sqr*sqr)%mod;
  if(e&1)return (resp*b)%mod;
  return resp;
}
 
int countReplacement(int n, int inputSeq[])
{
  vector<ll>big;
  if(!valid(n,inputSeq))return 0;

  for(int i=0;i<n;++i){
    if(inputSeq[i]>n)big.pb(ll(inputSeq[i]));
  }
  
  sort(all(big));

  ll res = 1, last = n;
  
  for(int i=0;i<sz(big);++i){
    res = (res*fastexp(ll(sz(big)-i),ll(big[i]-last-1)))%mod, last = big[i];
  }
  ll tam = (sz(big)==n?ll(sz(big)):1);
  res = (res*tam)%mod;
  return res;
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 16 ms 3004 KB Output is correct
7 Correct 8 ms 1088 KB Output is correct
8 Correct 23 ms 5472 KB Output is correct
9 Correct 9 ms 1876 KB Output is correct
10 Correct 35 ms 6060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 12 ms 3020 KB Output is correct
7 Correct 8 ms 1108 KB Output is correct
8 Correct 23 ms 5464 KB Output is correct
9 Correct 8 ms 1960 KB Output is correct
10 Correct 36 ms 6084 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 15 ms 2240 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 42 ms 5668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 960 KB Output is correct
12 Correct 10 ms 980 KB Output is correct
13 Correct 12 ms 1380 KB Output is correct
14 Correct 8 ms 1004 KB Output is correct
15 Correct 18 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 4708 KB Output is correct
10 Correct 37 ms 4148 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 14 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 41 ms 4728 KB Output is correct
10 Correct 33 ms 4088 KB Output is correct
11 Correct 11 ms 1600 KB Output is correct
12 Correct 14 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 46 ms 5296 KB Output is correct
15 Correct 58 ms 5940 KB Output is correct
16 Correct 11 ms 1288 KB Output is correct
17 Correct 36 ms 4052 KB Output is correct
18 Correct 24 ms 2680 KB Output is correct