Submission #530268

#TimeUsernameProblemLanguageResultExecution timeMemory
530268gg123_peGondola (IOI14_gondola)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; typedef long long ll; #define f(i,a,b) for(int i = a; i < b; i++) const int N = 250005; const ll mod = 1e9 + 9; int cant[N], m[N]; bool on[N]; int valid(int n, int X[]){ f(i,0,n) cant[X[i]]++; int ct = 0, id; f(i,1,N) { if(cant[i] > 1) return 0; if(i <= n and cant[i]) ct++; } if(ct == 0) return 1; f(i,0,n) if(X[i] <= n) id = i; vector <int> a, v1, v2; int pr = X[id]-1; f(i,0,n-id){ pr++; if(pr == n+1) pr = 1; v2.push_back(pr); } f(i,0,id){ pr++; if(pr == n+1) pr = 1; v1.push_back(pr); } for(int x: v1) a.push_back(x); for(int x: v2) a.push_back(x); int ans = 1; f(i,0,n) if(X[i] <= n and a[i] != X[i]) ans = 0; return ans; } int replacement(int n, int X[], int res[]){ int id = -1; f(i,0,n) if(X[i] <= n) id = i; vector <int> a, v1, v2; if(id != -1){ int pr = X[id]-1; f(i,0,n-id){ pr++; if(pr == n+1) pr = 1; v2.push_back(pr); } f(i,0,id){ pr++; if(pr == n+1) pr = 1; v1.push_back(pr); } for(int x: v1) a.push_back(x); for(int x: v2) a.push_back(x); } else f(i,0,n) a.push_back(i+1); int maxi = 0; f(i,0,n) { if(X[i] > n) m[X[i]] = a[i], on[X[i]] = 1; maxi = max(maxi, X[i]); } vector <int> ans; id = n+1; while(id <= maxi){ int l = id; while(!on[id]) id++; ans.push_back(m[id]); f(i,l,id) ans.push_back(i); id++; } int l = ans.size(); f(i,0,l) res[i] = ans[i]; return l; } ll bp(ll x, ll y){ if(y == 0) return 1; ll ans = bp(x, y/2); ans = (ans*ans)%mod; if(y%2 == 0) return ans; return (ans*x)%mod; } int countReplacement(ll n, int X[]){ if(!valid(n, X)) return 0; ll ans = 1; vector <ll> v = {n}; f(i,0,n) if(X[i] > n) v.push_back(X[i]); sort(v.begin(), v.end()); ll l = v.size(); for(ll i = 1; i < l; i++) ans = (ans*bp(l+1-i, v[i]-v[i-1]-1))%mod; if(v.size() > n) ans = (ans*n)%mod; return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(ll, int*)':
gondola.cpp:98:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   98 |     if(v.size() > n) ans = (ans*n)%mod;
      |        ~~~~~~~~~^~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:24:16: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     int pr = X[id]-1;
      |                ^~
/usr/bin/ld: /tmp/ccU1Fsmn.o: in function `main':
grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
collect2: error: ld returned 1 exit status