Submission #118005

#TimeUsernameProblemLanguageResultExecution timeMemory
118005rajarshi_basuJousting tournament (IOI12_tournament)C++14
0 / 100
1070 ms1764 KiB
#include <iostream> #include <vector> #include <set> #include <iomanip> #include <algorithm> #include <functional> #include <stdio.h> #include <cmath> #include <queue> #include <string> #include <map> #include <fstream> #include <complex> #include <stack> #include <set> #define FOR(i,n) for(int i=0;i<n;i++) #define FORE(i,a,b) for(int i=a;i<=b;i++) #define ll long long int #define vi vector<int> #define ii pair<int,int> #define pb push_back #define mp make_pair #define ff first #define ss second #define pll pair<ll,ll> #define cd complex<double> #define ld long double #define pld pair<ld,ld> #define iii pair<ii,int> using namespace std; const ll INF = 1e9+10; const int MAXN = 100*100*10+10; int elimArray[MAXN];//means after the ith cell, elimArray[i] had been eliminated. vector<ii> modifRange; int prevBest[MAXN]; int nextBest[MAXN]; int GetBestPosition(int n,int c,int r,int* arr,int* ss,int* ee){ // first modify the range to their actual sizes; // this step is O(n^2) for now. change to O(nlogn) later. FOR(i,c){ int s = ss[i]; int e = ee[i]; int ctr = 0; FORE(j,s,e+ctr){ ctr += elimArray[j]; } modifRange.pb({s,e+ctr}); elimArray[s] += e - s; } // now for each position, find its closest left and right element greater than r; // this step is already O(n) int bestFound = -1; FOR(i,n-1){ prevBest[i] = bestFound; if(arr[i] > r)bestFound = i; } prevBest[n-1] = bestFound; bestFound = n; for(int i = n-2;i>=0;i--){ nextBest[i+1] = bestFound; if(arr[i] > r)bestFound = i; } nextBest[0] = bestFound; /* FOR(i,n-1)cout << arr[i] << " ";cout << endl; for(auto e: modifRange){ cout << e.ff << " " << e.ss << endl; } cout << endl; FOR(i,n)cout << prevBest[i] << " ";cout << endl; FOR(i,n)cout << nextBest[i] << " ";cout << endl; */ int mx = 0; FOR(i,n){ int hit = 0; for(auto e : modifRange){ if(e.ss < i or e.ff > i)continue; //int mm = 0; //FORE(j,e.ff,e.ss-1)mm = max(arr[j],mm); if(e.ff <= prevBest[i] or e.ss >= nextBest[i]+1){ break; } hit++; } //cout <<i << " " << hit << endl; mx = max(mx,hit); } return mx; } int mai1n(){ int arr[7] = {1,0,2,3,4,6}; int s[4] = {2,1,0,0}; int e[4] = {4,2,2,1}; cout << GetBestPosition(7,4,5,arr,s,e) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...