Submission #417746

#TimeUsernameProblemLanguageResultExecution timeMemory
417746vanicGondola (IOI14_gondola)C++14
100 / 100
87 ms6308 KiB
#include "gondola.h" #include <cmath> #include <algorithm> #include <vector> #include <map> #include <cassert> #include <iostream> using namespace std; typedef long long ll; const int maxn=1e5+5, mod=1e9+9, Log=30; inline int sum(int a, int b){ if(a+b>=mod){ return a+b-mod; } if(a+b<0){ return a+b+mod; } return a+b; } inline int mul(int a, int b){ return (ll)a*b%mod; } inline int pot(int a, int b){ int sol=1; for(int i=0; i<Log; i++){ if((1<<i)&b){ sol=mul(sol, a); } a=mul(a, a); } return sol; } int poc[maxn]; map < int, int > bio; int valid(int n, int l[]){ for(int i=0; i<n; i++){ if(bio[l[i]]){ return 0; } bio[l[i]]=1; poc[i]=i+1; } bio.clear(); int pos=-1; for(int i=0; i<n; i++){ if(l[i]<=n){ pos=i; break; } } if(pos==-1){ return 1; } int val=l[pos]; for(int i=0; i<n; i++){ poc[pos]=val; val=(val+1)%n; pos=(pos+1)%n; if(!val){ val=n; } } for(int i=0; i<n; i++){ if(l[i]<=n && poc[i]!=l[i]){ return 0; } } return 1; } int replacement(int n, int l[], int sol[]){ assert(valid(n, l)); int maksi=0, ind; for(int i=0; i<n; i++){ bio[l[i]]=i; if(maksi<l[i]){ maksi=l[i]; ind=i; } } int pos=0; for(int i=n+1; i<=maksi; i++){ if(bio.find(i)!=bio.end()){ sol[pos]=poc[bio[i]]; poc[bio[i]]=i; } else{ sol[pos]=poc[ind]; poc[ind]=i; } pos++; } bio.clear(); return maksi-n; } //---------------------- int countReplacement(int n, int l[]){ if(!valid(n, l)){ return 0; } bool nema=1; for(int i=0; i<n; i++){ if(l[i]<=n){ nema=0; break; } } sort(l, l+n); vector < int > v; v.push_back(n); int p=-1; for(int i=0; i<n; i++){ if(l[i]>n){ if(p==-1){ p=n-i; } v.push_back(l[i]); } } int sol=1; for(int i=0; i<(int)v.size()-1; i++){ sol=mul(sol, pot(p, v[i+1]-v[i]-1)); p--; } if(nema){ sol=mul(sol, n); } return sol; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:98:20: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   98 |    sol[pos]=poc[ind];
      |             ~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...