Submission #770141

#TimeUsernameProblemLanguageResultExecution timeMemory
770141tigarGondola (IOI14_gondola)C++14
100 / 100
46 ms9964 KiB
#include "gondola.h" #include <bits/stdc++.h> //💖 using namespace std; typedef long long ll; ll MOD=1000000009; map<int, bool>check; map<int, int>convent; vector<int>ord; ll powerOptimised(ll a, ll n) { int res=1; while(n>0) { int last_bit=(n&1); if(last_bit)res=(res*a)%MOD; a=(a*a)%MOD; n=n>>1; } return res; } int valid(int n, int* inputSeq) { int last=-1, pos=-1; for(int i=0; i<n; i++) { if(inputSeq[i]<=n and last==-1){last=inputSeq[i]; pos=i;} else if(inputSeq[i]<=n) { if((last+i-pos)%n==(inputSeq[i])%n){last=inputSeq[i]; pos=i;} else {return 0;} } else if(check[inputSeq[i]])return 0; check[inputSeq[i]]=true; } return 1; } int replacement(int n, int* gondolaSeq, int* replacementSeq) { int maks=-1, g=-1, k=1; for(int i=0; i<n; i++) { //cout<<gondolaSeq[i]<<" "<<n<<endl; if(gondolaSeq[i]>n) { convent[gondolaSeq[i]]=i+1; if(gondolaSeq[i]>maks){maks=gondolaSeq[i]; g=i;} } else {k=i;} } for(int i=0; i<n; i++) { gondolaSeq[i]=(gondolaSeq[k]+i-k+n)%n; if(gondolaSeq[i]==0)gondolaSeq[i]=n; } if (maks==-1)return 0; for(int i=n+1; i<=maks; i++) { if(convent[i]==0){replacementSeq[i-n-1]=gondolaSeq[g]; gondolaSeq[g]=i;} else{replacementSeq[i-n-1]=gondolaSeq[convent[i]-1]; gondolaSeq[convent[i]-1]=i;} } return maks-n; } int countReplacement(int n, int* inputSeq) { int last=-1, pos=-1; for(int i=0; i<n; i++) { if(inputSeq[i]<=n and last==-1){last=inputSeq[i]; pos=i;} else if(inputSeq[i]<=n) { if((last+i-pos)%n==(inputSeq[i])%n){last=inputSeq[i]; pos=i;} else {return 0;} } else if(check[inputSeq[i]])return 0; check[inputSeq[i]]=true; } int cnt=0; ll maks=0; for(int i=0; i<n; i++) { if(inputSeq[i]>n) { cnt++; ord.push_back(inputSeq[i]); if(inputSeq[i]>maks){maks=inputSeq[i];} } } sort(ord.begin(), ord.end()); ll res=1, pp=0; for(int i=0; i<ord.size(); i++) { if(i==0)res=(res*powerOptimised(ord.size()-i, ord[i]-n-1))%MOD; else {res=(res*powerOptimised(ord.size()-i, ord[i]-ord[i-1]-1))%MOD;} } if(ord.size()==n)res=(res*n)%MOD; return res; } /*int main() { int n; cin>>n; int gondole[n]; for(int i=0; i<n; i++)cin>>gondole[i]; cout<<countReplacement(n, gondole)<<endl; //for(int i=0; i<11; i++)cout<<zamena[i]<<" "; }*/

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:97:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0; i<ord.size(); i++)
      |                  ~^~~~~~~~~~~
gondola.cpp:102:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |     if(ord.size()==n)res=(res*n)%MOD;
      |        ~~~~~~~~~~^~~
gondola.cpp:95:15: warning: unused variable 'pp' [-Wunused-variable]
   95 |     ll res=1, pp=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...