Submission #874233

#TimeUsernameProblemLanguageResultExecution timeMemory
874233MatjazJousting tournament (IOI12_tournament)C++14
49 / 100
1050 ms2188 KiB
#include <vector> #include <algorithm> #include <iostream> using namespace std; // Insight: each S[i] E[i] corresponds to some interval in the original set of positions // The interval only matters if your player is in it - and there is a unique answer as to whether it wins or loses // You can find the best position with a sweep. int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { vector<int> s(N+1); s[0] = 0; for (int i=1;i<=N;i++) s[i] = s[i-1] + (K[i-1] > R); vector<pair<int,int> > sweep_events; vector<pair<int,int> > positions(N); vector<pair<int,int> > intervals(C); for (int i=0;i<N;i++) positions[i] = make_pair(i,i); for (int i=0;i<C;i++){ intervals[i] = make_pair(positions[S[i]].first, positions[E[i]].second); positions[S[i]] = intervals[i]; for (int j=E[i]+1;j<N;j++) positions[S[i] + j - E[i]] = positions[j]; if (s[intervals[i].second] - s[intervals[i].first] == 0){ sweep_events.push_back(make_pair(intervals[i].first, 1)); sweep_events.push_back(make_pair(intervals[i].second + 1, -1)); } } sort(sweep_events.begin(), sweep_events.end()); int best_position = 0; int best_wins = 0; int wins = 0; for (int i=0;i<sweep_events.size();i++){ wins += sweep_events[i].second; if (wins > best_wins){ best_wins = wins; best_position = sweep_events[i].first; } } return best_position; }

Compilation message (stderr)

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=0;i<sweep_events.size();i++){
      |                  ~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...