Submission #466583

# Submission time Handle Problem Language Result Execution time Memory
466583 2021-08-19T17:11:31 Z Carmel_Ab1 Gondola (IOI14_gondola) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;

#include "gondola.h"
#include "grader.cpp"
#define pb push_back
#define all(x) x.begin(),x.end()
#define print(x) {for(auto it:x){cout << it << " "; }cout << "\n";}
int valid(int n, int inputSeq[]){
    vi a(n);
    for(int i=0; i<n; i++)
        a[i]=inputSeq[i];
    vi s(a);
    sort(all(s));
    for(int i=0; i<n-1; i++)
        if(s[i]==s[i+1])
            return 0;
    int f=-1;
    for(int i=0; i<n; i++)
        if(a[i]<=n)
            f=i;
    for(int i=0; i<n; i++)
        if(a[i]<=0)
            return 0;
    if(f==-1)return 1;
    for(int i=0,j=a[f]; i<n; j=((j%n) +1),i++){
        int cur=a[(i+f)%n];
        if(cur!=j && cur<=n)
            return 0;
    }
    return 1;
}

int replacement(int n, int a[], int rep[]){
    vi ans,org(n+1);
    int f=-1;
    for(int i=0; i<n; i++)
        if(a[i]<=n)
            f=i;
    if(f==-1)
        for(int i=0; i<n; i++)
            org[i]=i+1;
    else
        for(int i=0,j=a[f]; i<n; j=((j%n) +1),i++){
            int cur=a[(i+f)%n];
            org[(i+f)%n]=j;
        }
    vector<pair<int,int>>s;
    for(int i=0; i<n; i++)
        s.push_back({a[i],i});
    sort(all(s));
    vector<bool>has(250001);
    for(int i=0; i<n; i++)
        has[a[i]]=1;
    for(int i=0,j=n+1; i<n; i++){
        if(s[i].first<=n)continue;
        ans.pb(org[s[i].second]);
        while(!has[j]){
            has[j]=1;
            ans.pb(j);
            j++;
        }
        j++;
    }

    for(int i=0; i<ans.size(); i++)
        rep[i]=ans[i];
    return ans.size();
}
ll power(ll a,ll b,ll m){
    if(b==0)return 1;
    else if(b==1)return a;
    ll r=power(a,b/2,m);
    ll ans=(r*r)%m;
    if(b%2)ans=(ans*a)%m;
    return ans;
}
int countReplacement(int n, int inputSeq[]){
    if(!valid(n,inputSeq))
        return 0;
    vi a(n);
    for(int i=0; i<n ;i++)
        a[i]=inputSeq[i];
    sort(all(a));
    const ll m=1e9+9;
    ll ans=1,cnt=0;
    for(int i=0; i<n; i++)
        if(a[i]>n)
            cnt++;
    for(int i=n+1; cnt>1; i++){
        if(binary_search(all(a),i))
            cnt--;
        else
            ans=(ans*cnt)%m;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:47:17: warning: unused variable 'cur' [-Wunused-variable]
   47 |             int cur=a[(i+f)%n];
      |                 ^~~
gondola.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=0; i<ans.size(); i++)
      |                  ~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccDZvseR.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cczbSxVR.o:gondola.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccDZvseR.o:(.bss+0xf4260): multiple definition of `gondolaSequence'; /tmp/cczbSxVR.o:(.bss+0xf4260): first defined here
/usr/bin/ld: /tmp/ccDZvseR.o:(.bss+0x0): multiple definition of `replacementSequence'; /tmp/cczbSxVR.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status