Submission #902865

# Submission time Handle Problem Language Result Execution time Memory
902865 2024-01-11T03:39:59 Z Muhammad_Aneeq Gondola (IOI14_gondola) C++17
55 / 100
49 ms 9944 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include "gondola.h"
using namespace std;
int valid(int n, int inputSeq[])
{
	vector<pair<int,int>>s={};
	map<int,int>d;
	for (int i=0;i<n;i++)
	{
		d[inputSeq[i]]++;
		if (inputSeq[i]<=n)
			s.push_back({inputSeq[i],i});
	}
	for (auto i:d)
	{
		if (i.second>1)
			return 0;
	}
	for (int i=0;i<s.size()-1;i++)
	{
		int z=s[i+1].second-s[i].second;
		if (((s[i+1].first-z+n-1)%n)+1==s[i].first)
			continue;
		return 0;
	}	
	return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int z=0;
	map<int,int>d;
	for (int i=0;i<n;i++)	
	{
		d[gondolaSeq[i]]++;
		z=max(z,gondolaSeq[i]);
	}
	vector<int>f;
	for (int i=n+1;i<z;i++)
	{
		if (d.find(i)==d.end())
			f.push_back(i);
		else
			if (d[i]>1)
				return 0;
	}
	int ind=0,val=1;
	for (int i=0;i<n;i++)
	{
		if (gondolaSeq[i]<=n)
		{
			ind=i;
			val=gondolaSeq[i];
		}
	}
	int req=(ind+n+1-val)%n;
	vector<pair<int,int>>w;
	for (int i=0;i<n;i++)
		w.push_back({gondolaSeq[i],i});
	sort(begin(w),end(w));
	map<int,int>in;
	for (int i=1;i<=n;i++)
	{
		in[req++]=i;
		req%=n;
	}
	int g=0;
	reverse(begin(f),end(f));
	for (int i=0;i<n;i++)
	{
		if (d[in[w[i].second]]==0)
		{
			replacementSeq[g++]=in[w[i].second];
		}
		while (f.size()&&f.back()<w[i].first)
		{
			replacementSeq[g++]=f.back();
			f.pop_back();
		}
	}
	return g;
}
int countReplacement(int n, int inputSeq[])
{
	return 0;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i=0;i<s.size()-1;i++)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 8 ms 2520 KB Output is correct
7 Correct 22 ms 4300 KB Output is correct
8 Correct 24 ms 4728 KB Output is correct
9 Correct 5 ms 1752 KB Output is correct
10 Correct 18 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 8 ms 2532 KB Output is correct
7 Correct 22 ms 4280 KB Output is correct
8 Correct 17 ms 5088 KB Output is correct
9 Correct 5 ms 1764 KB Output is correct
10 Correct 19 ms 5336 KB Output is correct
11 Correct 0 ms 360 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 29 ms 5320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 508 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 1 ms 576 KB Output is correct
8 Correct 1 ms 392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 42 ms 8648 KB Output is correct
12 Correct 49 ms 9944 KB Output is correct
13 Correct 46 ms 5812 KB Output is correct
14 Correct 41 ms 8660 KB Output is correct
15 Correct 33 ms 4720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -