답안 #1001343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001343 2024-06-18T22:01:44 Z ZeroCool 곤돌라 (IOI14_gondola) C++14
55 / 100
25 ms 5144 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

#define ar array

int valid(int n, int A[]){
	int B[n];
	int p;
	
	set<int> s;
	for(int i = 0;i < n;i++)s.insert(A[i]);
	if(s.size() < n)return 0;
	
	for(int i = 0;i< n;i++){
		if(A[i] <= n){
			p = i;
			B[i] = A[i];
			break;
		}
	}
	
	for(int i = p + 1;i < n;i++){
		B[i] = B[i-1] + 1;
	}
	for(int i = p - 1;i >= 0;i--){
		B[i] = B[i + 1] - 1;
	}
	
	for(int i = 0;i < n;i ++){
		if(B[i] > n) B[i] -= n;
		if(B[i] <= 0) B[i] += n;
	}
	
	for(int i = 0;i<n;i++){
		if(A[i] > n)continue;
		if(A[i] != B[i])return 0;
	}
	
	return 1;
}

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

int replacement(int n, int A[], int ans[]){
	int o = 0;
	for(int i = 0;i < n;i++){
		if(A[i] > n)o++;
	}
	vector<ar<int, 2> > v;
	if(o == n){
		for(int i = 0;i < n;i++)v.push_back({A[i], i + 1});
	}else{
		int B[n];
		int p;
		
		for(int i = 0;i< n;i++){
			if(A[i] <= n){
				p = i;
				B[i] = A[i];
				break;
			}
		}
		
		for(int i = p + 1;i < n;i++){
			B[i] = B[i-1] + 1;
		}
		for(int i = p - 1;i >= 0;i--){
			B[i] = B[i + 1] - 1;
		}
		
		for(int i = 0;i < n;i ++){
			if(B[i] > n) B[i] -= n;
			if(B[i] <= 0) B[i] += n;
		}
		
		for(int i = 0;i < n;i++){
			if(A[i] > n)v.push_back({A[i], B[i]});
		}
		
		
	}
	sort(v.begin(), v.end());
	int c = n + 1;
	int cnt = 0;
	for(auto [x, i]: v){
		ans[cnt++] = i;
		while(c != x){
			ans[cnt++] = c++;
		}
		c++;
	}
	return cnt;
}

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

int countReplacement(int n, int inputSeq[])
{
  return -3;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:14:14: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |  if(s.size() < n)return 0;
      |     ~~~~~~~~~^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:87:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |  for(auto [x, i]: v){
      |           ^
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:24:10: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |  for(int i = p + 1;i < n;i++){
      |          ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:66:11: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |   for(int i = p + 1;i < n;i++){
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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
# 결과 실행 시간 메모리 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
6 Correct 7 ms 2396 KB Output is correct
7 Correct 19 ms 3932 KB Output is correct
8 Correct 14 ms 4116 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 18 ms 4888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 19 ms 4072 KB Output is correct
8 Correct 13 ms 4184 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 17 ms 4748 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 9 ms 2368 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 25 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 5 ms 1372 KB Output is correct
12 Correct 6 ms 1624 KB Output is correct
13 Correct 9 ms 1608 KB Output is correct
14 Correct 5 ms 1372 KB Output is correct
15 Correct 12 ms 2360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 600 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -