Submission #289211

# Submission time Handle Problem Language Result Execution time Memory
289211 2020-09-02T13:07:11 Z Shafin666 Gondola (IOI14_gondola) C++14
55 / 100
47 ms 4728 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^・ω・^=)"
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
 
const int maxn = 3e5+10;
 
int next(int p, int n) {
	int ret = (p + 1) % n;
	return (ret == 0)? n : ret;
}
 
int prev(int p, int n) {
	if(p == 0) return n-1;
	else return p-1;
}
 
int valid(int n, int inputSeq[])
{
	int f = 1, prev = -1;
	for(int i = 0; i < n; i++) {
		if(inputSeq[i] >= 1 && inputSeq[i] <= n) {
			if(prev == -1) prev = inputSeq[i];
			else if(next(prev, n) == inputSeq[i]) prev = inputSeq[i];
			else f = 0;
		}
	}
 
	set<int> s;
	for(int i = 0; i < n; i++) s.insert(inputSeq[i]);
	if(s.size() != n) return 0;
 
  	return f;
}
 
//----------------------
 
int pos[maxn];
 
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	memset(pos, -1, sizeof pos);
 
	vector<int> v, dummy, target(n);
	int mx = 0, none = 1;
 
	for(int i = 0; i < n; i++) {
		if(gondolaSeq[i] > n) {
			dummy.pb(i);
			pos[gondolaSeq[i]] = i;
			mx = max(mx, gondolaSeq[i]);
		}
		else none = 0;
	}

	for(int i = 0; i < n; i++) target[i] = gondolaSeq[i];
 
	if(!none) {
		for(int i = 0; i < n; i++) {
			if(gondolaSeq[prev(i, n)] >= 1 && gondolaSeq[prev(i, n)] <= n)
				gondolaSeq[i] = next(gondolaSeq[prev(i, n)], n);
		}
 
		for(int i = 0; i < n; i++) {
			if(gondolaSeq[prev(i, n)] >= 1 && gondolaSeq[prev(i, n)] <= n)
				gondolaSeq[i] = next(gondolaSeq[prev(i, n)], n);
		}
	}
	else {
		for(int i = 0; i < n; i++) gondolaSeq[i] = i+1;
	}
 
	for(int i = n+1, d = 0; i <= mx; i++) {
		if(pos[i] == -1) {
			while(gondolaSeq[dummy[d]] == target[dummy[d]]) d++;
			v.pb(gondolaSeq[dummy[d]]), gondolaSeq[dummy[d]] = i;
		}
		else v.pb(gondolaSeq[pos[i]]), gondolaSeq[pos[i]] = i;
	} 
 
	int idx = 0;
	for(auto i : v) replacementSeq[idx++] = i;
 
  	return v.size();
}
 
//----------------------
 
int countReplacement(int n, int inputSeq[])
{
  	return -3;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:37:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |  if(s.size() != n) return 0;
      |     ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 18 ms 2176 KB Output is correct
7 Correct 47 ms 3704 KB Output is correct
8 Correct 25 ms 3960 KB Output is correct
9 Correct 7 ms 1536 KB Output is correct
10 Correct 28 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 12 ms 2176 KB Output is correct
7 Correct 32 ms 3704 KB Output is correct
8 Correct 29 ms 4128 KB Output is correct
9 Correct 7 ms 1536 KB Output is correct
10 Correct 28 ms 4608 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 17 ms 2048 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 42 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 2 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 2 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
11 Correct 12 ms 2560 KB Output is correct
12 Correct 18 ms 2688 KB Output is correct
13 Correct 16 ms 2812 KB Output is correct
14 Correct 12 ms 2560 KB Output is correct
15 Correct 26 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 288 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -