Submission #1071689

#TimeUsernameProblemLanguageResultExecution timeMemory
1071689cpdreamerGondola (IOI14_gondola)C++14
55 / 100
12 ms2616 KiB
#include "gondola.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <utility> using namespace std; typedef long long ll; #define V vector #define F first #define S second #define P pair #define pb push_back #define all(v) v.begin(),v.end() int valid(int n, int inputSeq[]) { int id=-1; for(int i=0;i<n;i++){ if(inputSeq[i]==1) { id = i; break; } } if(id==-1) return 0; int c=2; for(int i=(id+1)%n;i!=id;i=(i+1)%n){ if(inputSeq[i]!=c) return 0; c++; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int id = -1, val; for (int i = 0; i < n; i++) { if (gondolaSeq[i] <= n) { id = i; val = gondolaSeq[i]; break; } } P<int, int> original[n]; if (id != -1) { original[id].S = val; original[id].F = gondolaSeq[id]; val=(val+1)%(n+1); if(val==0) val=1; for (int i = (id + 1) % n; i != id; i = (i + 1) % n) { original[i].S = val; original[i].F = gondolaSeq[i]; val=(val+1)%(n+1); if(val==0) val=1; } } else { for (int i = 0; i < n; i++) { original[i].S = i + 1; original[i].F = gondolaSeq[i]; } } int limit = n + 1; V<int> replace; sort(original, original + n); for (int i = 0; i < n; i++) { if (original[i].F != original[i].S) { replace.pb(original[i].S); for (int j = limit; j < original[i].F; j++) { replace.pb(j); } limit = original[i].F+1; } } for(int i=0;i<replace.size();i++){ replacementSeq[i]=replace[i]; } return (int)replace.size(); } //---------------------- int countReplacement(int n, int inputSeq[]) { if(valid(n,inputSeq)==0) return 0; ll ans=1; ll mod=1e9+9; sort(inputSeq,inputSeq+n); for(int i=n+1;i<= *max_element(inputSeq,inputSeq+n)-1;i++){ int l=0,r=n-1; int v=-1; while(l<=r){ int m=l+(r-l)/2; if(inputSeq[m]>=i){ v=m; r=m-1; } else{ l=m+1; } } if(v!=-1) { if (inputSeq[v] != i) { ans = (ans * (n - v)) % mod; } } } if(*min_element(inputSeq,inputSeq+n)>n){ ans=(ans*n)%mod; } ans=ans%mod; return (int)ans; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=0;i<replace.size();i++){
      |                 ~^~~~~~~~~~~~~~~
#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...