답안 #773559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773559 2023-07-05T06:47:24 Z loctildore 곤돌라 (IOI14_gondola) C++14
컴파일 오류
0 ms 0 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
// trans rights
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
#define MOD 1000000009

int valid(int n, int inputSeq[])
{
    int tmp = -1;
    set<int> st;
    for (int i = 0; i < n; i++) {
        if (inputSeq[i] <= n) {
            int cur = (inputSeq[i] - i + n) % n;
            if (tmp == -1) tmp = cur;
            if (tmp != cur) return 0;
        }
        else {
            if (st.find(inputSeq[i]) != st.end()) return 0;
            st.insert(inputSeq[i]);
        }
    }
    return 1;
}

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

int ori[100069];
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int offst = 1;
    pair<int,int> maxi = {0, -1};
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] <= n) {
            offst = gondolaSeq[i] - i;
        }
        maxi = max(maxi, {gondolaSeq[i], i});
    }
    for (int i = 0; i < n; i++) {
        ori[i] = (i + offst + n) % n;
        if (ori[i] == 0) ori[i] = n;
    }
    int l = maxi.f - n;
    for (int i = 0; i < l; i++) {
        replacementSeq[i] = -1;
    }
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] > n && gondolaSeq[i] != maxi.f) {
            replacementSeq[gondolaSeq[i] - n - 1] = ori[i];
        }
    }
    int cur = ori[maxi.s];
    for (int i = 0; i < l; i++) {
        if (~replacementSeq[i]) continue;
        replacementSeq[i] = cur;
        cur = i + n + 1;
    }
    return l;
}

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

int pow(int x, int y) {
    if (y == 0) return 0;
    if (y % 2) return x * pow(x, y - 1);
    int tmp = pow(x, y / 2);
    return (tmp * tmp) % MOD;
}

int countReplacement(int n, int inputSeq[])
{
    vector<int> vctr= {n};
    int rtn = n;
    for (int i = 0; i < n; i++) {
        if (inputSeq[i] > n) vctr.push_back(inputSeq[i]);
        else rtn = 1;
    }
    sort(all(vctr));
    int tmp = vctr.size();
    for (int i = 1; i < vctr.size(); i++) {
        rtn = (rtn * pow(tmp - i, vctr[i] - vctr[i - 1] - 1)) % MOD;
    }
    return rtn;
}

Compilation message

gondola.cpp: In function 'long long int countReplacement(long long int, long long int*)':
gondola.cpp:84:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (int i = 1; i < vctr.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/cchIxYfr.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status