Submission #182565

# Submission time Handle Problem Language Result Execution time Memory
182565 2020-01-10T01:38:09 Z FieryPhoenix Gondola (IOI14_gondola) C++11
60 / 100
48 ms 4228 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
#include "gondola.h"
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000009


int valid(int N, int arr[]){
  unordered_set<int>st;
  int pos=-1;
  for (int i=0;i<N;i++){
    if (st.count(arr[i]))
      return 0;
    st.insert(arr[i]);
    if (arr[i]<=N)
      pos=i;
  }
  if (pos==-1)
    return 1;
  for (int i=0;i<N;i++){
    int j=(pos+i)%N;
    int target=arr[pos]+i;
    if (target>N)
      target-=N;
    if (arr[j]<=N && arr[j]!=target)
      return 0;
  }
  return 1;
}


bool used[250001];
int should[100001];
 
int replacement(int N, int g[], int repl[]){
  int nex=0;
  for (int i=0;i<N;i++){
    should[i]=i+1;
    nex=max(nex,g[i]);
  }
  int pos=-1;
  for (int i=0;i<N;i++)
    if (g[i]<=N)
      pos=i;
  for (int i=pos;i<pos+N;i++){
    int x=g[pos]+i-pos;
    if (x>N) x-=N;
    should[i%N]=x;
  }
  vector<int>v;
  for (int i=0;i<N;i++)
    used[g[i]]=true;
  priority_queue<pair<int,int>>pq;
  for (int i=0;i<N;i++)
    pq.push({g[i],i});
  while (!pq.empty()){
    int ind=pq.top().second;
    pq.pop();
    if (g[ind]<=N)
      continue;
    while (used[nex])
      nex--;
    if (nex<=N)
      nex=should[ind];
    v.push_back(nex);
    used[nex]=true;
    g[ind]=nex;
    pq.push({g[ind],ind});
  }
  reverse(v.begin(),v.end());
  for (int i=0;i<(int)v.size();i++)
    repl[i]=v[i];
  return (int)v.size();
}

int countReplacement(int n, int a[]){
  if (valid(n,a)==0)
    return 0;
  ll ans=1;
  vector<int>v;
  int mx=0;
  for (int i=0;i<n;i++)
    if (a[i]>n){
      mx=max(mx,a[i]);
      v.push_back(a[i]);
    }
  sort(v.begin(),v.end());
  for (int i=(int)v.size()-1;i>=0;i--){
    ll r=v[i]-1;
    ll l=n+1;
    if (i>0)
      l=v[i-1]+1;
    if (r>=l){
      ll num=(int)v.size()-i;
      ans=(ans*((num*(r-l+1))%MOD))%MOD;
    }
  }
  int pos=-1;
  for (int i=0;i<n;i++)
    if (a[i]<=n)
      pos=i;
  if (pos==-1)
    ans=(ans*n)%MOD;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 12 ms 1960 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 21 ms 3724 KB Output is correct
9 Correct 8 ms 1272 KB Output is correct
10 Correct 24 ms 4100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 12 ms 2088 KB Output is correct
7 Correct 12 ms 760 KB Output is correct
8 Correct 22 ms 3720 KB Output is correct
9 Correct 8 ms 1400 KB Output is correct
10 Correct 24 ms 4104 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 15 ms 1960 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 31 ms 4228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 0 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 19 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 23 ms 2248 KB Output is correct
12 Correct 26 ms 2288 KB Output is correct
13 Correct 34 ms 1820 KB Output is correct
14 Correct 22 ms 2160 KB Output is correct
15 Correct 48 ms 2620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -