Submission #138781

# Submission time Handle Problem Language Result Execution time Memory
138781 2019-07-30T10:18:56 Z Mahmoud_Adel Gondola (IOI14_gondola) C++14
5 / 100
6 ms 4220 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5, mod = 1e9+9;
int mep[N];
ll power(ll a, ll b)
{
	if(!b) return 1;
	ll temp = power(a, b/2);
	temp = (temp*temp)%mod;
	if(b%2) temp *= a, temp %= mod;
	return temp;
}
int valid(int n, int inputSeq[])
{
	sort(inputSeq, inputSeq+n);
	for(int i=0; i<n-1; i++) if(inputSeq[i] == inputSeq[i+1]) return 0;
	int j = -1;
	for(int i=0; i<n; i++) if(inputSeq[i] > 0 && inputSeq[i] <= n) j = i;
	if(j == -1) return 1;
	for(int i=0; i<n; i++)
	{
		int id = (i+j)%n, jd = (i+j+1)%n;
		if(inputSeq[jd] > n) inputSeq[jd] = inputSeq[id]%n + 1;
		if(inputSeq[jd] != inputSeq[id]%n + 1) return 0;
	}
	return 1;
}

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

int replacement(int n, int inputSeq[], int replacementSeq[])
{
	memset(mep, 0, sizeof mep);
	int j = -1, c = n;
	for(int i=0; i<n; i++) if(inputSeq[i] <= n) j  = i;
	if(j == -1)
	{
		for(int i=0; i<n; i++)
		{
			int id = (i+j) % n, jd = (i+j+1) % n;
			c = max(c, inputSeq[jd]), mep[inputSeq[jd]] = i+1;
		}
		int last = -1;
		for(int i=n+1; i<c; i++)
		{
			if(mep[i]) replacementSeq[i-n-1] = mep[i];
			else replacementSeq[i-n-1] = mep[c], last = i;
		}
		if(last != -1) replacementSeq[c-n-1] = last;
		else replacementSeq[c-n-1] = mep[c];
		return c-n;	
	}
	for(int i=0; i<n; i++)
	{
		int id = (i+j) % n, jd = (i+j+1) % n;
		if(inputSeq[jd] > n) c = max(c, inputSeq[jd]), 
		mep[inputSeq[jd]] = inputSeq[id]%n + 1, inputSeq[jd] = inputSeq[id]%n + 1;
	}
	int last = -1;
	for(int i=n+1; i<c; i++)
	{
		if(mep[i]) replacementSeq[i-n-1] = mep[i];
		else replacementSeq[i-n-1] = mep[c], last = i;
	}
	if(last != -1) replacementSeq[c-n-1] = last;
	else replacementSeq[c-n-1] = mep[c];
	return c-n;
}

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

int countReplacement(int n, int inputSeq[])
{
	int tmp[n];
	for(int i=0; i<n; i++) tmp[i] = inputSeq[i];
	if(!valid(n, inputSeq)) return 0;
	for(int i=0; i<n; i++) inputSeq[i] = tmp[i];
	ll j = -1, c = n;
	vector<ll> vec;
	for(int i=0; i<n; i++) if(inputSeq[i] <= n) j  = i;
	else vec.push_back(inputSeq[i]);
	ll ans = 1;
	vec.push_back(n);
	sort(vec.begin(), vec.end());
	for(int i=0; i<vec.size()-1; i++)
	{
		ll tmp = power((ll)vec.size()-i-1, vec[i+1]-vec[i]-1);
		ans = (ans%mod * tmp%mod)%mod;
	}
	return (ans*(j==-1? n:1))%mod;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:42:8: warning: unused variable 'id' [-Wunused-variable]
    int id = (i+j) % n, jd = (i+j+1) % n;
        ^~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:87:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vec.size()-1; i++)
               ~^~~~~~~~~~~~~
gondola.cpp:80:13: warning: unused variable 'c' [-Wunused-variable]
  ll j = -1, c = n;
             ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 5 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 6 ms 4216 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Incorrect 6 ms 4216 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 6 ms 4188 KB Output is correct
5 Correct 5 ms 4188 KB Output is correct
6 Incorrect 6 ms 4216 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -