답안 #163477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163477 2019-11-13T14:02:07 Z ioane 곤돌라 (IOI14_gondola) C++14
55 / 100
29 ms 3708 KB
#include "gondola.h"/**/
#include <bits/stdc++.h>
#define LL long long
#define PB push_back
#define FOR(i,n) for (int i = 0; i < (n); i++)

const LL N = 100005, NR = 250005;

using namespace std;

LL m, i, j, k, l, r, t;
LL a[N], fox[NR], b[N];
bool fix[NR];

int valid(int n, int inputSeq[]){
	t = 0;
	for ( i = 1; i <= n; ++i ){
		if ( fix[inputSeq[i-1]] ) return 0;
		//cout << inputSeq[i-1] << " " << fix[inputSeq[i-1]] << endl;
		fix[inputSeq[i-1]] = 1;
		if ( inputSeq[i-1] <= n ){
			t = inputSeq[i-1] - i;
		}
	}
	//if ( t == NR ) return 1;
	for ( i = 1; i <= n; ++i ){
		j = i + t;
		while ( j < 1 ) j += n;
		while ( j > n ) j -= n;
		a[j] = inputSeq[i-1];
	}
	for ( i = 1; i <= n; ++i ){
		if ( a[i] <= n && a[i] != i ) return 0;
	}
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	valid(n, gondolaSeq);
	t = 0;
	for ( i = 1; i <= n; ++i ){
		fox[a[i]] = i;
		if ( t < a[i] ){
			t = a[i];
		}
		b[i] = i;
	}
	//cout << n << " " << t << endl;
	for ( i = n + 1; i <= t; ++i ){
		if ( !fox[i] ){
			replacementSeq[i - n - 1] = b[fox[t]];
			b[fox[t]] = i;
		}
		else{
			replacementSeq[i - n - 1] = b[fox[i]];
			b[fox[i]] = i;
		} 
		m++;
	}
	return m;
}

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

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


/*/



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

int main()
{
	freopen ( "te.txt", "r", stdin);
  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;
}
/**/

Compilation message

gondola.cpp:114:1: warning: "/*" within comment [-Wcomment]
 /**/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 7 ms 756 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 12 ms 1272 KB Output is correct
9 Correct 14 ms 632 KB Output is correct
10 Correct 13 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 7 ms 860 KB Output is correct
7 Correct 15 ms 760 KB Output is correct
8 Correct 11 ms 1272 KB Output is correct
9 Correct 14 ms 632 KB Output is correct
10 Correct 13 ms 1400 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 8 ms 1032 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 15 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 14 ms 3064 KB Output is correct
12 Correct 29 ms 3448 KB Output is correct
13 Correct 17 ms 2808 KB Output is correct
14 Correct 14 ms 2936 KB Output is correct
15 Correct 24 ms 3708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -