제출 #126797

#제출 시각아이디문제언어결과실행 시간메모리
126797ekremGondola (IOI14_gondola)C++98
55 / 100
61 ms2944 KiB
#include "gondola.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, mx, a[N], u[N];


int valid(int n, int a[]){
	int x = inf;
	for(int i = 0; i < n; i++){
		a[i]--;
		if(u[a[i]])return 0;
		u[a[i]] = 1;
		if(a[i] < n and a[i] >= 0){
			if(x != inf and x != (a[i] - i + n)%n )
				return 0;
			x = (a[i] - i + n)%n;
		}
	}
	return 1;
}

int replacement(int n, int a[], int b[]){
	int m = -1, x = 0;
	priority_queue < ii > q;
	priority_queue < int > yok;
	for(int i = 0; i < n; i++){
		a[i]--;
		u[a[i]] = 1;
		mx = max(mx, a[i]);
		if(a[i] < n and a[i] >= 0)
			x = (a[i] - i + n)%n;
		else
			q.push(mp(a[i], i));
	}
	for(int i = n; i <= mx; i++)
		if(!u[i])
			yok.push(i);
	while(!q.empty()){
		int y = q.top().st;
		int ind = q.top().nd;
		q.pop();
		if(yok.empty())
			b[++m] = (x + ind)%n + 1;
		else{
			b[++m] = yok.top() + 1;
			q.push(mp(yok.top(), ind));
			yok.pop();
		}
	}
	reverse(b, b + m + 1);
	// for(int i = 0; i <= m; i++)
	// 	cout << "b"<<b[i] << " ";
 	return m + 1;
}

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

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




// int gondolaSequence[100001];
// int replacementSequence[250001];

// int main()
// {
// 	freopen("in.txt", "r", stdin);
// 	freopen("outt.txt", "w", stdout);
//   int i, n, tag;
//   int nr; 
//   assert(scanf("%d", &tag)==1);
//   assert(scanf("%d", &n)==1);
//   for(i=0;i< n;i++)
//     assert( scanf("%d", &gondolaSequence[i]) ==1);
  
//   switch (tag){
//   case 1: case 2: case 3:
//     printf("%d\n", valid(n, gondolaSequence));
//     break;

//   case 4: case 5: case 6:
//     nr = replacement(n, gondolaSequence, replacementSequence);
//     printf("%d ", nr);
//     if (nr > 0)
//       {
// 	for (i=0; i<nr-1; i++)
// 	  printf("%d ", replacementSequence[i]);
// 	printf("%d\n", replacementSequence[nr-1]);
//       }  
//     else printf("\n");
//     break;

//   case 7: case 8: case 9: case 10:
//     printf("%d\n",  countReplacement(n, gondolaSequence));  
//     break;
//   }

//   return 0;
// }

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:54:7: warning: unused variable 'y' [-Wunused-variable]
   int y = q.top().st;
       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...