Submission #243897

#TimeUsernameProblemLanguageResultExecution timeMemory
243897aloo123Gondola (IOI14_gondola)C++14
45 / 100
42 ms4856 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #include <gondola.h> #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define pll pair<ll,ll> #define f first #define s second // #define int ll #define sz(x) (ll)x.size() #define all(x) (x.begin(),x.end()) using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os; const ll INF = 1e18; const ll N =(1e5+5); // TODO : change value as per problem const ll MOD = 1e9+9; int valid(int n, int a[]){ ll spare = n+1; set<ll> se; ll nxt = a[0]; se.in(nxt); nxt++; if(nxt > n) nxt = 1; // ll spare =n; for(int i = 1;i<n;i++){ if(se.find(a[i]) != se.end()) return 0; if(a[i] <= n){ if(a[i] != nxt) return 0; se.in(a[i]); } else{ spare = a[i]; } nxt++; if(nxt > n) nxt = 1; } return 1; } int replacement(int n, int a[], int replacementSeq[]) { ll idx = 0; bool original = 0; for(int i =0;i<n;i++){ if(a[i] <= n){ idx =i; original = true; break; } } int b[n]; vector<int> ans; vector<pair<int,int>> gg; ll count = 1; ll nxt = a[idx]; if(original == false) nxt = 1; // cout << idx << endl; while(count <= n){ b[idx] = nxt; nxt++; idx++; if(nxt > n) nxt = 1; if(idx >= n) idx = 0; count++; } ll sp = n+1; // for(int i =0;i<n;i++) cout << b[i] << " ";cout<<endl; for(int i =0;i<n;i++){ if(a[i] > n) gg.pb({a[i],b[i]}); } sort(gg.begin(),gg.end()); for(int i = 0;i<sz(gg);i++){ ans.pb(gg[i].s); ll x = sp; while(x != gg[i].f){ ans.pb(x); x++; } sp = gg[i].f+1; } // for(int i = 0;i<sz(ans);i++) cout<<ans[i]<<" ";cout<<endl; for(int i = 0;i<sz(ans);i++) replacementSeq[i] = ans[i]; return sz(ans); } int countReplacement(int n, int inputSeq[]) { //cout << "QQA\n"; if(!valid(n,inputSeq)) return 0; //cout<<"QQA\n"; ll special = 0; vll v; for(int i =0;i<n;i++){ if(inputSeq[i] > n){ special += 1; v.pb(inputSeq[i]); } } if(special == 0) return 1; ll ans = n; if(special != n) ans = 1; sort(v.begin(),v.end()); for(int i = n+1;i<=v.back();i++){ ll cnt = 0; for(int j = 0;j<sz(v);j++) { if(v[j] == i){ cnt = 1; break; } else if(v[j] > i) cnt++; } // cout << i << " " << cnt << endl; ans = (ans * cnt)%MOD; } return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:61:8: warning: variable 'spare' set but not used [-Wunused-but-set-variable]
     ll spare = n+1;
        ^~~~~
#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...