This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int a[])
{
int sm = INT_MAX, pos = -1;
map<int,int> M; M.clear();
for(int i = 0; i < n; i++)
{
M[a[i]]++;
if(M[a[i]]>=2)return 0;
}
for(int i = 0; i < n; i++)
if(sm>a[i] and a[i]<=n)sm=a[i], pos=i;
if(sm==INT_MAX)return 1;
int x = n;
while(x--){
if(a[pos]==n and a[(pos+1)%n]<=n and a[(pos+1)%n]!=1)return 0;
else if(a[pos]<n and a[(pos+1)%n]<=n and a[pos]!=a[(pos+1)%n]-1) return 0;
pos++, pos%=n;
}
return 1;
}
int replacement(int n, int a[], int b[])
{
map<int,int> M; M.clear();
set<int> S; S.clear();
vector<int> v; v.clear();
int x = n, pos = 0, mx = 0;
for(int i = 0; i < n; i++) S.insert(a[i]), mx = max(mx, a[i]);
for(int i = 0; i < n; i++)
if(a[i]<=n) pos = (i-a[i]+n+1)%n;
int z = 1; while(x--) M[a[pos]]=z, z++, pos++, pos%=n;
for(int i = n+1; i <= mx; i++){
if(S.count(i)) v.push_back(M[i]), M[i]=i;
else{
int x = *S.lower_bound(i);
v.push_back(M[x]), M[x]=i;
}
}
for(int i = 0; i < (int)v.size(); i++) b[i]=v[i];
return (int)v.size();
}
int poww(int a, int b, int MOD=1e9+7)
{
if(b==0)return 1ll;
int x = poww(a, b/2);
x*=x; x%=MOD;
return (x*(b%2?a:1ll))%MOD;
}
int countReplacement(int n, int a[])
{
if(!valid(n, a)) return 0;
if(*max_element(a, a+n)==n)return 1;
vector<int> v; v.clear();
for(int i = 0; i < n; i++) if(a[i]>n)v.push_back(a[i]);
sort(v.begin(), v.end()); int m = (int)v.size();
int ans = poww(m, v[m-1]-v[0]-m);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |