Submission #599278

# Submission time Handle Problem Language Result Execution time Memory
599278 2022-07-19T12:20:24 Z Koosha_mv Gondola (IOI14_gondola) C++14
100 / 100
49 ms 7176 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99,mod=1e9+9;

map<int,int> mark;

ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}

int valid(int n, int inputSeq[]){
  f(i,0,n) inputSeq[i]--;
  f(i,0,n) if(++mark[inputSeq[i]]>1) return 0;
  f(i,0,n){
    if(inputSeq[i]<n){
      f(j,0,n){
        if(inputSeq[(i+j)%n]!=(inputSeq[i]+j)%n && inputSeq[(i+j)%n]<n) return 0;
      }
      return 1;
    }
  }
  return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
  vector<pair<int,int>> vec;
  f(i,0,n) gondolaSeq[i]--;
  int b=0,l=0;
  f(i,0,n){
    if(gondolaSeq[i]<n){
      b=1;
      f(j,0,n){
        if(gondolaSeq[(i+j)%n]>=n){
          vec.pb(mp(gondolaSeq[(i+j)%n],(gondolaSeq[i]+j)%n));
        }
      }
      break ;
    }
  }
  if(b==0){
    f(i,0,n){
      vec.pb({gondolaSeq[i],i});
    }
  }
  sort(all(vec));
  int prv=n-1;
  for(auto p : vec){
    replacementSeq[l++]=p.S;
    f(i,prv+1,p.F) replacementSeq[l++]=i;
    prv=p.F;
  }
  f(i,0,l) replacementSeq[i]++;
  return l;
}

//----------------------

int countReplacement(int n, int inputSeq[])
{
  vector<pair<int,int>> vec;
  f(i,0,n) inputSeq[i]--;
  f(i,0,n) if(++mark[inputSeq[i]]>1) return 0;
  int b=0;
  f(i,0,n){
    if(inputSeq[i]<n){
      b=1;
      f(j,0,n){
        if(inputSeq[(i+j)%n]!=(inputSeq[i]+j)%n && inputSeq[(i+j)%n]<n){
          return 0;
        }
        if(inputSeq[(i+j)%n]>=n){
          vec.pb(mp(inputSeq[(i+j)%n],(inputSeq[i]+j)%n));
        }
      }
      break ;
    }
  }
  if(b==0){
    f(i,0,n){
      vec.pb({inputSeq[i],i});
    }
  }
  sort(all(vec));
  int prv=n-1,ans=1;
  f(i,0,vec.size()){
    pair<int,int> p=vec[i];
    int cnt=vec.size()-i;
    //cout<<cnt<<" -> "<<p.F-prv<<endl;
    ans=1ll*ans*pow(cnt,p.F-prv-1,mod)%mod;
    prv=p.F;
  }
  if(b==0){
    ans=1ll*ans*n%mod;
  }
  return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
  106 |   f(i,0,vec.size()){
      |     ~~~~~~~~~~~~~~             
gondola.cpp:106:3: note: in expansion of macro 'f'
  106 |   f(i,0,vec.size()){
      |   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2148 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 17 ms 3940 KB Output is correct
9 Correct 6 ms 1380 KB Output is correct
10 Correct 21 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 11 ms 2132 KB Output is correct
7 Correct 12 ms 556 KB Output is correct
8 Correct 18 ms 3924 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 21 ms 4436 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 12 ms 2004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 28 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 596 KB Output is correct
12 Correct 8 ms 596 KB Output is correct
13 Correct 12 ms 1188 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 19 ms 2164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 33 ms 4680 KB Output is correct
10 Correct 24 ms 4052 KB Output is correct
11 Correct 12 ms 1752 KB Output is correct
12 Correct 14 ms 2004 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 31 ms 4636 KB Output is correct
10 Correct 27 ms 4004 KB Output is correct
11 Correct 11 ms 1808 KB Output is correct
12 Correct 12 ms 2076 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 48 ms 5612 KB Output is correct
15 Correct 49 ms 7176 KB Output is correct
16 Correct 8 ms 1748 KB Output is correct
17 Correct 32 ms 4684 KB Output is correct
18 Correct 17 ms 3116 KB Output is correct