Submission #320315

#TimeUsernameProblemLanguageResultExecution timeMemory
320315tigichaGondola (IOI14_gondola)C++17
60 / 100
54 ms6756 KiB
#include "gondola.h" #include<bits/stdc++.h> using namespace std; const int mod=1e9+9; long long k, l, b[100005], sum; map <long long,long long> mp; long long pow(long long x, long long y){ long long s=1; while(y>0){ if(y%2==1) s=(s*x)%mod; x=(x*x)%mod; y/=2; } return s; } int valid(int n, int a[]){ l=-1; for(int i=0; i<n; i++) if(mp[a[i]]==1) return 0; else mp[a[i]]=1; for(int i=0; i<n; i++) if(a[i]<=n){ l=i; break; } if(l==-1) return 1; k=a[l]; for(int i=l; i<n; i++) if(a[i]!=k && a[i]<=n) return 0; else{ k++; if(k==n+1) k=1; } for(int i=0; i<l; i++) if(a[i]!=k && a[i]<=n) return 0; else{ k++; if(k==n+1) k-=n; } return 1; } int replacement(int n, int a[], int ans[]){ l=-1; for(int i=0; i<n; i++) if(a[i]<=n){ l=i; break; } k=a[l]; for(int i=l; i<n; i++){ b[i]=k; k++; if(k==n+1) k-=n; } for(int i=0; i<l; i++){ b[i]=k; k++; if(k==n+1) k=1; } vector<pair<int, int> >v; for(int i=0; i<n; i++) if(a[i]>n) v.push_back({a[i], i}); sort(v.begin(), v.end()); l=n; k=0; for(int i=0; i<v.size(); i++) while(b[v[i].second]<a[v[i].second]){ ans[k]=b[v[i].second]; k++; l++; b[v[i].second]=l; } return k; } int countReplacement(int n, int a[]){ if(valid(n, a)==0) return 0; vector<int>vec; vec.push_back(n); for(int i=0; i<n; i++) if(a[i]>n) vec.push_back(a[i]); sort(vec.begin(), vec.end()); sum=1; for(int i=0; i<vec.size()-1; i++){ sum*=pow(vec.size()-i-1, vec[i+1]-vec[i]-1); sum%=mod; } if(vec.size()==n+1) sum=(sum*n)%mod; return sum; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i=0; i<v.size(); i++)
      |                  ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:83:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0; i<vec.size()-1; i++){
      |                  ~^~~~~~~~~~~~~
gondola.cpp:87:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |     if(vec.size()==n+1) sum=(sum*n)%mod;
      |        ~~~~~~~~~~^~~~~
#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...