Submission #118604

# Submission time Handle Problem Language Result Execution time Memory
118604 2019-06-19T09:42:47 Z Plurm Last supper (IOI12_supper) C++11
0 / 100
2500 ms 12552 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;

int FT[100005];
void add(int idx, int amt){
    idx++;
    while(idx < 100005){
        FT[idx] += amt;
        idx += idx & -idx;
    }
}
int sum(int idx){
    idx++;
    int ret = 0;
    while(idx > 0){
        ret += FT[idx];
        idx -= idx & -idx;
    }
    return ret;
}
int nxt[100005];
set<int> s[100005];
void ComputeAdvice(int *C, int N, int K, int M) {
    const int INF = 1e9;
    // Compute everything in the morning.
    // Remember only ordering of the removals.
    for(int i = 0; i < N; i++){
        s[C[i]].insert(i);
    }
    for(int i = 0; i < N; i++){
        set<int>::iterator it = s[C[i]].upper_bound(i);
        if(it == s[C[i]].end()){
            nxt[i] = INF;
        }else{
            nxt[i] = *it;
        }
    }
    set<int> use;
    vector<int> raw;
    for(int i = 0; i < K; i++){
        use.insert(i);
        add(i,1);
    }
    for(int i = 0; i < N; i++){
        if(use.find(C[i]) != use.end()){
            raw.push_back(K);
        }else{
            int curuse = -1;
            int nxtpos = 0;
            for(set<int>::iterator it = use.begin(); it != use.end(); ++it){
                int col = *it;
                set<int>::iterator nxt = s[col].upper_bound(i);
                if(nxt == s[col].end()){
                    curuse = col;
                    break;
                }
                if(*nxt > nxtpos){
                    nxtpos = *nxt;
                    curuse = col;
                }
            }
            raw.push_back(sum(curuse));
            use.erase(curuse);
            add(curuse, -1);
            use.insert(C[i]);
            add(C[i], 1);
        }
    }
    for(int i = 0; i < raw.size(); i++){
        for(int j = 0; j < 15; j++){
            if(raw[i] & (1 << j)){
                WriteAdvice(1);
            }else{
                WriteAdvice(0);
            }
        }
    }
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;

int FTS[100005];
void addS(int idx, int amt){
    idx++;
    while(idx < 100005){
        FTS[idx] += amt;
        idx += idx & -idx;
    }
}
int sumS(int idx){
    idx++;
    int ret = 0;
    while(idx > 0){
        ret += FTS[idx];
        idx -= idx & -idx;
    }
    return ret;
}
int getidx(int num){
    int lo = 0;
    int hi = 100003;
    int mid;
    while(lo < hi){
        mid = (lo + hi)/2;
        if(sumS(mid) < num){
            lo = mid+1;
        }else{
            hi = mid;
        }
    }
    return lo;
}
void Assist(unsigned char *A, int N, int K, int R) {
    vector<int> dat;
    for(int i = 0; i < R; i += 15){
        int cur = 0;
        for(int j = 0; j < 15; j++){
            if(A[i+j]){
                cur += 1 << j;
            }
        }
        dat.push_back(cur);
    }
    set<int> use;
    for(int i = 0; i < K; i++){
        use.insert(i);
        addS(i,1);
    }
    for(int i = 0; i < N; i++){
        int cur = GetRequest();
        if(use.find(cur) != use.end()) continue;
        int now = dat[i];
        int eidx = getidx(now);
        PutBack(eidx);
        use.erase(eidx);
        addS(eidx, -1);
        use.insert(cur);
        addS(cur, 1);
    }
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:70:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < raw.size(); i++){
                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10240 KB Output is correct
2 Correct 8 ms 10240 KB Output is correct
3 Correct 11 ms 10496 KB Output is correct
4 Correct 18 ms 10752 KB Output is correct
5 Incorrect 10 ms 10752 KB Error - advice is too long
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 12528 KB Output is correct
2 Execution timed out 2541 ms 8832 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2532 ms 11144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 10752 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2535 ms 12240 KB Time limit exceeded
2 Execution timed out 2534 ms 12336 KB Time limit exceeded
3 Execution timed out 2535 ms 12544 KB Time limit exceeded
4 Execution timed out 2553 ms 12380 KB Time limit exceeded
5 Execution timed out 2554 ms 12492 KB Time limit exceeded
6 Execution timed out 2551 ms 12536 KB Time limit exceeded
7 Execution timed out 2547 ms 12548 KB Time limit exceeded
8 Execution timed out 2555 ms 12552 KB Time limit exceeded
9 Execution timed out 2521 ms 12380 KB Time limit exceeded
10 Execution timed out 2543 ms 12412 KB Time limit exceeded