# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
428406 | Amylopectin | Gondola (IOI14_gondola) | C++14 | 30 ms | 2980 KiB |
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 <iostream>
#include <stdio.h>
#include <algorithm>
#include "gondola.h"
//#include "grader.cpp"
using namespace std;
const long long mxn = 2e6 + 10,mo = 1e9 + 9;
struct we
{
long long stn,thn;
};
bool cmp(const struct we &l,const struct we &r)
{
return l.thn < r.thn;
}
struct we so[mxn] = {};
int u[mxn] = {};
int valid(int n, int inp[])
{
long long i,j,m,stp = -1,of = 0;
for(i=0; i<n; i++)
{
if(stp == -1 && inp[i] <= n)
{
stp = i - inp[i] + 1;
if(stp < 0)
{
stp += n;
}
}
if(stp >= 0 && inp[i] <= n)
{
if((stp + inp[i] - 1) % n != i)
{
of = 1;
break;
}
}
}
for(i=0; i<n; i++)
{
if(u[inp[i]] == 1)
{
of = 1;
break;
}
else
{
u[inp[i]] = 1;
}
}
if(of == 0)
{
return 1;
}
return 0;
}
int replacement(int n, int inp[], int ans[])
{
long long i,j,ru = 0,stp = -1,fr,ba,rua = 0;
for(i=0; i<n; i++)
{
if(stp == -1 && inp[i] <= n)
{
stp = i - inp[i] + 1;
if(stp < 0)
{
stp += n;
}
break;
}
}
if(stp == -1)
{
stp = 0;
}
for(i=0; i<n; i++)
{
if(inp[i] > n)
{
so[ru] = {(i + n - stp) % n + 1,inp[i]};
ru ++;
}
}
sort(so,so+ru,cmp);
fr = 0;
ba = 0;
// while(ba < ru)
// {
// }
for(i=n+1; i<=so[ru-1].thn; i++)
{
if(i == so[fr].thn)
{
ans[rua] = so[fr].stn;
rua ++;
fr ++;
// if(ba < fr)
// {
// ba = fr;
// }
}
else
{
ans[rua] = so[fr].stn;
so[fr].stn = i;
rua ++;
}
}
return rua;
}
int countReplacement(int n, int inp[])
{
long long i,j,m,stp = -1,of = 0,ans = 1,be,ru = 0,off = 0,cva,cdif,fva;
for(i=0; i<n; i++)
{
if(stp == -1 && inp[i] <= n)
{
stp = i - inp[i] + 1;
if(stp < 0)
{
stp += n;
}
}
if(stp >= 0 && inp[i] <= n)
{
if((stp + inp[i] - 1) % n != i)
{
of = 1;
break;
}
}
}
// for(i=0; i<n; i++)
// {
// if(u[inp[i]] == 1)
// {
// of = 1;
// break;
// }
// else
// {
// u[inp[i]] = 1;
// }
// }
if(of == 1)
{
return 0;
}
if(stp == -1)
{
off = 1;
ans *= n;
stp = 0;
}
for(i=0; i<n; i++)
{
if(inp[i] > n)
{
so[ru] = {(i + n - stp) % n + 1,inp[i]};
ru ++;
}
}
sort(so,so+ru,cmp);
be = n;
for(i=0; i<ru; i++)
{
if(so[i].thn == be)
{
return 0;
}
cdif = so[i].thn - be - 1;
cva = ru-i;
j = 0;
while(1)
{
fva = (1 << j) & cdif;
if(fva > 0)
{
ans *= cva;
ans %= mo;
}
j ++;
cva = cva * cva;
cva %= mo;
fva = (1 << j);
if(fva > cdif)
{
break;
}
}
// for(j=be+1; j<so[i].thn; j++)
// {
// ans *= ru-i;
// ans %= mo;
// }
be = so[i].thn;
}
return ans;
// return -3;
}
//int main()
//{
//
// return 0;
//}
Compilation message (stderr)
# | 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... |