제출 #118004

#제출 시각아이디문제언어결과실행 시간메모리
118004rajarshi_basu마상시합 토너먼트 (IOI12_tournament)C++14
0 / 100
1046 ms3116 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;

}

컴파일 시 표준 에러 (stderr) 메시지

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:17:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(i,n) for(int i=0;i<n;i++)
                  ^
tournament.cpp:70:2: note: in expansion of macro 'FOR'
  FOR(i,n-1)cout << arr[i] << " ";cout << endl;
  ^~~
tournament.cpp:70:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  FOR(i,n-1)cout << arr[i] << " ";cout << endl;
                                  ^~~~
tournament.cpp:17:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(i,n) for(int i=0;i<n;i++)
                  ^
tournament.cpp:75:2: note: in expansion of macro 'FOR'
  FOR(i,n)cout << prevBest[i] << " ";cout << endl;
  ^~~
tournament.cpp:75:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  FOR(i,n)cout << prevBest[i] << " ";cout << endl;
                                     ^~~~
tournament.cpp:17:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(i,n) for(int i=0;i<n;i++)
                  ^
tournament.cpp:76:2: note: in expansion of macro 'FOR'
  FOR(i,n)cout << nextBest[i] << " ";cout << endl;
  ^~~
tournament.cpp:76:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  FOR(i,n)cout << nextBest[i] << " ";cout << endl;
                                     ^~~~
tournament.cpp: In function 'int mai1n()':
tournament.cpp:104:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...