This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <queue>
#include <map>
#include "gondola.h"
#define maxn 1005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define mod 1000000009
#define control cout<<"passed"<<endl;
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double ld;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
int valid(int n, int a[])
{
map <int , int> br;
int minn = INF , idx;
for(int i = 0; i < n; i++)
{
if(minn > a[i])
{
minn = a[i];
idx = i;
}
br[a[i]]++;
if(br[a[i]] > 1)
return false;
}
if(minn > n)
return true;
int curr = minn + 1;
for(int i = idx + 1; i % n != idx; i++)
{
if(a[i % n] <= n && a[i % n] != curr)
return false;
curr++;
}
return true;
}
int replacement(int n, int a[], int r[])
{
int idx = 0;
int delta = INF;
vector <pii> v;
for(int i = 0; i < n; i++)
{
if(a[i] <= n && a[i] < delta)
{
delta = a[i];
idx = i;
}
if(a[i] > n)
v.push_back({a[i] , i});
}
if(delta == INF)
delta = 1;
sort(v.begin() , v.end());
int next = n + 1 , curr = 0;
int old;
for(auto& e : v)
{
if(e.Y < idx)
old = n - idx + e.Y + delta;
else
old = e.Y - idx + delta;
old %= n;
if(old == 0)
old = n;
r[curr] = old;
curr++;
while(next != e.X)
{
r[curr] = next;
next++;
curr++;
}
next = e.X + 1;
}
return curr;
}
ll power(ll base , ll p)
{
ll ans = 1;
while(p != 0)
{
if(p % 2 == 1)
ans *= base , ans %= mod;
base *= base;
base %= mod;
p /= 2;
}
return ans;
}
int countReplacement(int n, int a[])
{
map <int , int> br;
int minn = INF , maxx = -INF;
int idx , shit = 0;
vector <int> v;
for(int i = 0; i < n; i++)
{
if(minn > a[i])
{
minn = a[i];
idx = i;
}
br[a[i]]++;
if(br[a[i]] > 1)
return 0;
maxx = max(maxx , a[i]);
if(a[i] > n)
{
shit++;
v.pb(a[i]);
}
}
int curr = minn + 1;
for(int i = idx + 1; i % n != idx; i++)
{
if(a[i % n] <= n && a[i % n] != curr)
return false;
curr++;
}
ll ans = 1;
int old = n;
sort(v.begin() , v.end());
for(int& e : v)
{
ans *= power(shit , e - old - 1);
ans %= mod;
shit--;
old = e;
}
if(minn > n)
ans *= n , ans %= mod;
return ans;
}
/**int main()
{
#ifdef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
///startT = std::chrono::high_resolution_clock::now();
return 0;
}
*/
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:58:22: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | int minn = INF , idx;
| ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:193:13: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
193 | for(int i = idx + 1; i % n != idx; i++)
| ^
# | 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... |