Submission #830213

# Submission time Handle Problem Language Result Execution time Memory
830213 2023-08-18T23:59:12 Z Liudas Jousting tournament (IOI12_tournament) C++17
17 / 100
1000 ms 1876 KB
//#include <stdio.h>
//#include <stdlib.h>
//#include <assert.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <fstream>
//#include "tournament.h"
using namespace std;
vector<int> tree, alive;
int N;
void init(int K){
    N = 1;
    while(N <= K){
        N *= 2;
    }
    tree.assign(N * 2, 0);
    alive.assign(N * 2, 0);
}
void add_alive(int head, int l, int r, int pos, int val){
    if(r - l == 1){
        alive[head] = val; 
        return;   
    }
    int mid = (l + r) / 2;
    if(pos < mid){
        add_alive(head * 2 + 1, l, mid, pos, val);
    }
    else{
        add_alive(head * 2 + 2, mid, r, pos, val);
    }
    alive[head] = alive[head * 2 + 1] + alive[head * 2 + 2];
}
void add_alive(int pos, int val){
    add_alive(0, 0, N, pos, val);
}
int get_alive(int head, int l, int r, int need, int left){
    //cout << l << " " << r << " " << need << " " << alive[head] + left << endl;
    if(r - l == 1){
        return l;   
    }
    int mid = (l + r) / 2;
    if(need <= alive[head * 2 + 1] + left){
        return get_alive(head * 2 + 1, l, mid, need, left);
    }
    else{
        return get_alive(head * 2 + 2, mid, r, need, left + alive[head * 2 + 1]);
    }
}
int get_alive(int need){
    return get_alive(0, 0, N, need, 0);
}
void add_val(int head, int l, int r, int pos, int val){
    if(r - l == 1){
        tree[head] = val; 
        return;   
    }
    int mid = (l + r) / 2;
    if(pos < mid){
        add_val(head * 2 + 1, l, mid, pos, val);
    }
    else{
        add_val(head * 2 + 2, mid, r, pos, val);
    }
    tree[head] = max(tree[head * 2 + 1], tree[head * 2 + 2]);
}
void add_val(int pos, int val){
    add_val(0, 0, N, pos, val);
}
int get_val(int head, int l, int r, int L, int R){
    if(L <= l && R >= r){
        return tree[head];
    }
    if(L >= r || R <= l){
        return 0;
    }
    int mid = (l + r) / 2;
    return max(get_val(head * 2 + 1, l, mid, L, R), get_val(head * 2 + 2, mid, r, L, R));
}
int get_val(int l, int r){
    return get_val(0, 0, N, l, r);
}
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int GetBestPosition(int N, int C, int R, int K[], int S[], int E[]){
    startTime = getCurrentTime();
    init(N);
    vector<int> pref(N + 5);
    int ans = 0;
    int id = 0;
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < N; j ++){
            add_val(j+(j >= i), K[j]);
            add_alive(j, 1);
        }
        add_val(i, R);
        add_alive(N, 1);
        for(int j = 0; j < C; j ++){
            int s = get_alive(S[j] + 1), e = get_alive(E[j] + 2);
            if(get_val(s, e) == R){
                pref[s] ++;
                pref[e + 1]--; 
            }
            for(int k = S[j]; k < E[j]; k ++){
                add_alive(get_alive(S[j] + 2), 0);
            }
        }
        int p = 0;
        for(int j = 0; j < N; j ++){
            p += pref[j];
            pref[j] = 0;
            if(ans < p){
                ans = p;
                id = j;
            }
        }
    }
    //cout << getCurrentTime() - startTime << endl;
    return id;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 94 ms 288 KB Output is correct
4 Correct 109 ms 212 KB Output is correct
5 Correct 53 ms 212 KB Output is correct
6 Correct 97 ms 296 KB Output is correct
7 Correct 98 ms 292 KB Output is correct
8 Correct 102 ms 212 KB Output is correct
9 Correct 52 ms 212 KB Output is correct
10 Correct 61 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 212 KB Output is correct
2 Execution timed out 1081 ms 468 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 1876 KB Time limit exceeded
2 Halted 0 ms 0 KB -