# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242331 | cheeheng | Jousting tournament (IOI12_tournament) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
#include <bits/stdc++.h>
using namespace std;
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
//printf("here");
vector<int> X;
X.push_back(1);
for(int i = 0; i < N-1; i ++){
if(K[i] < R){
X.push_back(0);
}else{
X.push_back(2);
}
}
int ans = 0;
int bestIndx = -1;
for(int i = 0; i < N; i ++){
vector<int> Y;
for(int j: X){
Y.push_back(j);
}
/*for(int j: Y){
printf("%d", j);
}
printf("\n");
printf("i=%d\n", i);*/
int temp = 0;
for(int j = 0; j < C; j ++){
int max1 = 0;
for(int k = S[j]; k <= E[j]; k ++){
max1 = max(max1, Y[k]);
}
for(int k = S[j]; k <= E[j]; k ++){
Y.erase(Y.begin()+S[j]);
}
temp += (max1 == 1);
Y.insert(Y.begin()+S[j], max1);
/*for(int j: Y){
printf("%d", j);
}
printf("\n");*/
}
//printf("temp=%d\n", temp);
if(temp > ans){
ans = temp;
bestIndx = i;
}
if(i+1 < N){
swap(X[i], X[i+1]);
}
}
return bestIndx;
}
int main() {
int tmp;
/* Set input and output buffering */
char *inbuf, *outbuf;
inbuf = (char*) malloc(inbuf_len * sizeof(char));
outbuf = (char*) malloc(outbuf_len * sizeof(char));
tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
assert(tmp == 0);
tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
assert(tmp == 0);
int N, C, R;
int *K, *S, *E;
tmp = scanf("%d %d %d", &N, &C, &R);
assert(tmp == 3);
K = (int*) malloc((N-1) * sizeof(int));
S = (int*) malloc(C * sizeof(int));
E = (int*) malloc(C * sizeof(int));
int i;
for (i = 0; i < N-1; i++) {
tmp = scanf("%d", &K[i]);
assert(tmp == 1);
}
for (i = 0; i < C; i++) {
tmp = scanf("%d %d", &S[i], &E[i]);
assert(tmp == 2);
}
printf("%d\n", GetBestPosition(N, C, R, K, S, E));
return 0;
}