Submission #586806

# Submission time Handle Problem Language Result Execution time Memory
586806 2022-06-30T17:18:52 Z Red_Inside Gondola (IOI14_gondola) C++17
100 / 100
62 ms 6700 KB
#include "gondola.h"

#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define forn(j, i, n) for(int i = j; i <= n; ++i)
#define FOR(j, i, n) for(int i = j; i < n; ++i)
#define nfor(j, i, n) for(int i = n; i >= j; --i)
#define IOS ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define all(v) v.begin(), v.end()
#define pb push_back

const int maxn = 1e5+100;

//#define int ll
#define pii pair <int, int>
int inf = 1e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll a[maxn], b[maxn];

int valid(int n, int inputSeq[])
{
	map <int, int> was;
	forn(1, i, n)
	{
		a[i] = inputSeq[i-1];
		was[a[i]]++;
		if(was[a[i]] >= 2)
		{
			return 0;
		}
	}
	int start = -1;
	forn(1, i, n)
	{
		if(a[i] <= n)
		{
			start = i - a[i] + 1;
			break;
		}
	}
	if(start == -1) return 1;
	forn(1, i, n)
	{
		b[(i-start+n)%n+1] = a[i];
	}
	forn(1, i, n)
	{
		if(b[i] > n) continue;
		if(b[i] != i) return 0;
	}
	return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	forn(1, i, n)
	{
		a[i] = gondolaSeq[i-1];
	}
	int start = -1;
	forn(1, i, n)
	{
		if(a[i] <= n)
		{
			start = i - a[i] + 1;
			break;
		}
	}
	if(start == -1)
	{
		set <pii> st;
		forn(1, i, n)
		{
			if(a[i] > n)
			{
				st.insert({a[i], i});
			}
		}
		int cur = 0;
		while(st.size())
		{
			replacementSeq[cur] = st.begin()->s;
			cur++;
			while(n + cur < st.begin()->f)
			{
				replacementSeq[cur] = n + cur;
				cur++;
			}
			st.erase(st.begin());
		}
		return cur;
	}
	forn(1, i, n)
	{
		b[(i-start+n)%n+1] = a[i];
	}
	set <pii> st;
	forn(1, i, n)
	{
		if(b[i] > n)
		{
			st.insert({b[i], i});
		}
	}
	int cur = 0;
	while(st.size())
	{
		replacementSeq[cur] = st.begin()->s;
		cur++;
		while(n + cur < st.begin()->f)
		{
			replacementSeq[cur] = n + cur;
			cur++;
		}
		st.erase(st.begin());
	}
	return cur;
}

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

ll mod = 1e9+9;

ll binpow(ll a, ll n)
{
	if(n < 0)
	{
		cout << 1;
		exit(0);
	}
	ll res = 1;
	while(n)
	{
		if(n&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n /= 2;
	}
	return res;
}

int countReplacement(int n, int inputSeq[])
{
	if(!valid(n, inputSeq))
	{
		return 0;
	}
	
	forn(1, i, n)
	{
		a[i] = inputSeq[i-1];
	}
	int start = 0;
	forn(1, i, n)
	{
		if(a[i] <= n)
		{
			start = 1;
			break;
		}
	}
	vector <ll> vec;
	forn(1, i, n)
	{
		if(a[i] > n)
		{
			vec.pb(a[i]);
		}
	}
	ll ans = 1;
	ll last = n;
	sort(all(vec));
	for(ll i = 0; i < (int)vec.size(); ++i)
	{
		ans = ans * binpow((ll)(vec.size()) - i, vec[i] - last - 1) % mod;
		last = vec[i];
	}
	if(!start) ans = ans * n % mod;
	return ans;
}

Compilation message

gondola.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/STACK:16777216")
      |
# 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 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 340 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 12 ms 2772 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 23 ms 5016 KB Output is correct
9 Correct 7 ms 1848 KB Output is correct
10 Correct 32 ms 5836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 2812 KB Output is correct
7 Correct 12 ms 628 KB Output is correct
8 Correct 23 ms 4980 KB Output is correct
9 Correct 8 ms 1792 KB Output is correct
10 Correct 32 ms 5720 KB Output is correct
11 Correct 0 ms 280 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 16 ms 2640 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 38 ms 5936 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 340 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 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 11 ms 1764 KB Output is correct
12 Correct 10 ms 2004 KB Output is correct
13 Correct 18 ms 3044 KB Output is correct
14 Correct 7 ms 1748 KB Output is correct
15 Correct 21 ms 3132 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 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 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 43 ms 5148 KB Output is correct
10 Correct 34 ms 4364 KB Output is correct
11 Correct 12 ms 1740 KB Output is correct
12 Correct 16 ms 2116 KB Output is correct
13 Correct 4 ms 596 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 39 ms 5136 KB Output is correct
10 Correct 33 ms 4308 KB Output is correct
11 Correct 11 ms 1748 KB Output is correct
12 Correct 14 ms 2088 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 59 ms 5216 KB Output is correct
15 Correct 62 ms 6700 KB Output is correct
16 Correct 9 ms 1492 KB Output is correct
17 Correct 36 ms 4564 KB Output is correct
18 Correct 20 ms 3036 KB Output is correct