답안 #30344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30344 2017-07-23T09:11:26 Z ozaslan 곤돌라 (IOI14_gondola) C++14
컴파일 오류
0 ms 0 KB
#include "gondola.h"
#include <vector>
#include <map>
#include <algorithm>
#define MOD 1000000009
using namespace std;

int valid(int n, int inputSeq[])
{
	int bas = -1;
	for (int i = 0; i < n; i++)
		if(inputSeq[i] <= n) {
			bas = i;
			break;
		}

	int s = bas == -1 ? 1 : inputSeq[bas];
	bas = bas == -1 ? 0 : bas;

 	int bayrak = 1;
	for (int i = bas; i < n; i++, s++) {
        if(s == n+1) s = 1;
		if(inputSeq[i] != s && inputSeq[i] <= n) {
			bayrak = 0;
			break;
		}
	}

	for (int i = 0; i < bas; i++, s++) {
        if(s == n+1) s = 1;
		if(inputSeq[i] != s && inputSeq[i] <= n) {
			bayrak = 0;
			break;
		}
	}

    if(!bayrak) return 0;

    vector<int> v (inputSeq, inputSeq+n);
    sort(v.begin(), v.end());

    for(int i = 1; i < n; i++)
    	if(v[i] == v[i-1]) {
    		bayrak = 0;
    		break;
    	}

	return bayrak;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int bas = -1;
	for (int i = 0; i < n; i++)
		if(inputSeq[i] <= n) {
			bas = i;
			break;
		}
    
    if (bas == -1) {
        for(int i = 0; i < n; i++)
            replacementSeq[i] = i+1;
        return n;
    }

	int s = inputSeq[bas];
    vector<int> v;
    map<int, int> m;
    
	for (int i = bas; i < n; i++, s++) {
        if(s == n+1) s = 1;
		
		if(gondolaSeq[i] > n) {
            v.push_back(gondolaSeq[i]);
            m[gondolaSeq[i]] = s;;
		}
	}

	for (int i = 0; i < bas; i++, s++) {
        if(s == n+1) s = 1;
		if(gondolaSeq[i] > n) {
            v.push_back(gondolaSeq[i]);
            m[gondolaSeq[i]] = s;;
		}	
    }
    
    sort(v.begin(), v.end());
    
    int sayac = 0, s = n+1;
    for(int i=0; i < v.size(); i++) {
        replacementSeq[sayac] = m[v[i]];
        sayac++;
        
        while(s < v[i]) {
            replacementSeq[sayac] = s;
            sayac++; s++;
        }
        s++;
    }
    
    return sayac;
}

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

long long us(long long a, long long b) {
    if(b == 0) return 1;
	if(b == 1) return a;
	if(b & 1) return ( (us(a, b>>1) * us(a, b>>1) % MOD) * a) % MOD;
	return (us(a, b>>1) * us(a, b>>1)) % MOD;
}


int countReplacement(int n, int inputSeq[])
{
//    printf("%lld, %lld, %lld\n", us(2, 5), us(5, 3), us(10, 10));
  /*  for(int i = 0; i < n; i++)
        printf("%d ", inputSeq[i]);
    printf("\n");
*/
    if( !valid(n, inputSeq) ) return 0;

	vector<int> v;

	for (int i = 0; i < n; i++)
		if (inputSeq[i] > n) v.push_back(inputSeq[i]);

	sort(v.begin(), v.end());

  /*  for(int i = 0; i < v.size(); i++)
        printf("%d ", v[i]);
    printf("\n");
*/

	long long sonuc = 1;

	if (v.size() == n) sonuc = n;

	int onceki = n;
	for(int i = 0; i < v.size(); i++) {
		sonuc *= us(v.size()-i, v[i]-onceki-1);
		sonuc %= MOD;
		onceki = v[i];
	}

	return sonuc % MOD;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:57:6: error: 'inputSeq' was not declared in this scope
   if(inputSeq[i] <= n) {
      ^
gondola.cpp:68:10: error: 'inputSeq' was not declared in this scope
  int s = inputSeq[bas];
          ^
gondola.cpp:91:20: error: redeclaration of 'int s'
     int sayac = 0, s = n+1;
                    ^
gondola.cpp:68:6: note: 'int s' previously declared here
  int s = inputSeq[bas];
      ^
gondola.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i < v.size(); i++) {
                    ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:139:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (v.size() == n) sonuc = n;
               ^
gondola.cpp:142:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                   ^