Submission #589297

#TimeUsernameProblemLanguageResultExecution timeMemory
589297yutabiGondola (IOI14_gondola)C++14
75 / 100
32 ms5020 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define MOD 1000000009 #define pb push_back typedef long long ll; typedef pair <int,int> ii; int valid(int n, int s[]) { set <int> st; int diff=-1; bool flag=0; for(int i=0;i<n;i++) { st.insert(s[i]); if(s[i]<=n) { int num=(s[i]+n-i)%n; if(diff!=-1 && diff!=num) { flag=1; } diff=num; } } if(st.size()!=n) { flag=1; } if(flag) { return 0; } return 1; } //---------------------- int replacement(int n, int ss[], int res[]) { vector <ii> s; int diff=0; for(int i=0;i<n;i++) { if(ss[i]<=n) { diff=(ss[i]+n-i-1)%n; } else { s.pb(ii(ss[i],i)); } } sort(s.begin(),s.end()); int ans=0; int curr=n; for(int i=0;i<s.size();i++) { res[ans]=((s[i].second+diff)%n)+1; ans++; curr++; while(curr<s[i].first) { res[ans]=curr; ans++; curr++; } } return ans; } //---------------------- ll fast_pow(ll a, ll b) { ll res=1; ll curr=a; while(b) { if(b%2) { res*=curr; res%=MOD; } b/=2; curr*=curr; curr%=MOD; } return res; } int countReplacement(int n, int ss[]) { if(valid(n,ss)==0) { return 0; } ll ans=1; vector <ii> s; int diff=0; for(int i=0;i<n;i++) { if(ss[i]<=n) { diff=(ss[i]+n-i-1)%n; } else { s.pb(ii(ss[i],i)); } } sort(s.begin(),s.end()); ll curr=n; for(int i=0;i<s.size();i++) { ans*=fast_pow(s.size()-i, s[i].first-curr-1); ans%=MOD; curr=s[i].first; } return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:42:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |     if(st.size()!=n)
      |        ~~~~~~~~~^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:152:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp:133:9: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
  133 |     int diff=0;
      |         ^~~~
#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...