Submission #118627

# Submission time Handle Problem Language Result Execution time Memory
118627 2019-06-19T10:01:29 Z Plurm Last supper (IOI12_supper) C++11
32 / 100
534 ms 35664 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];
int infcnt;
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 + infcnt++;
        }else{
            nxt[i] = *it;
        }
    }
    map<int, int> use;
    map<int, int> f;
    vector<int> raw;
    for(int i = 0; i < K; i++){
        if(s[i].empty()){
            use[i] = INF + infcnt++;
            f[INF + infcnt-1] = i;
        }else{
            set<int>::iterator it = s[i].begin();
            use[i] = *it;
            f[*it] = i;
        }
        add(i,1);
    }
    for(int i = 0; i < N; i++){
        if(f.find(i) != f.end()){
            int x = f[i];
            set<int>::iterator it = s[x].upper_bound(i);
            f.erase(i);
            if(it == s[x].end()){
                use[x] = INF + infcnt++;
                f[INF + infcnt - 1] = x;
            }
            else{
                use[x] = *it;
                f[*it] = x;
            }
        }
        if(use.find(C[i]) != use.end()){
        }else{
            pair<int,int> cur = *f.rbegin();
            f.erase(cur.first);
            raw.push_back(sum(cur.second));
            use.erase(cur.second);
            add(cur.second, -1);
            use[C[i]] = nxt[i];
            f[nxt[i]] = C[i];
            add(C[i], 1);
        }
    }
    for(int i = 0; i < raw.size(); i++){
        for(int j = 0; j < 17; 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 += 17){
        int cur = 0;
        for(int j = 0; j < 17; 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);
    }
    int idx = 0;
    for(int i = 0; i < N; i++){
        int cur = GetRequest();
        if(use.find(cur) != use.end()) continue;
        int now = dat[idx++];
        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:80: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 9984 KB Output is correct
2 Correct 8 ms 9984 KB Output is correct
3 Correct 9 ms 10496 KB Output is correct
4 Correct 17 ms 10752 KB Output is correct
5 Incorrect 11 ms 11008 KB Error - advice is too long
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 12544 KB Output is correct
2 Correct 164 ms 19680 KB Output is correct
3 Correct 506 ms 35664 KB Output is correct
4 Correct 418 ms 33768 KB Output is correct
5 Correct 432 ms 33120 KB Output is correct
6 Correct 427 ms 32176 KB Output is correct
7 Correct 432 ms 32776 KB Output is correct
8 Correct 398 ms 32888 KB Output is correct
9 Correct 380 ms 33032 KB Output is correct
10 Correct 426 ms 33952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 319 ms 28088 KB Output is correct
2 Correct 440 ms 32920 KB Output is correct
3 Correct 445 ms 32880 KB Output is correct
4 Correct 417 ms 32152 KB Output is correct
5 Correct 382 ms 30288 KB Output is correct
6 Correct 445 ms 32616 KB Output is correct
7 Correct 417 ms 32464 KB Output is correct
8 Correct 482 ms 35600 KB Output is correct
9 Correct 281 ms 30504 KB Output is correct
10 Correct 403 ms 33224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 10752 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 433 ms 32368 KB Output is partially correct - 875347 bits used
2 Partially correct 408 ms 32296 KB Output is partially correct - 841041 bits used
3 Partially correct 428 ms 32792 KB Output is partially correct - 807466 bits used
4 Partially correct 409 ms 32616 KB Output is partially correct - 806939 bits used
5 Partially correct 417 ms 32504 KB Output is partially correct - 805358 bits used
6 Partially correct 409 ms 32624 KB Output is partially correct - 807109 bits used
7 Partially correct 401 ms 32616 KB Output is partially correct - 805902 bits used
8 Partially correct 438 ms 33104 KB Output is partially correct - 808452 bits used
9 Partially correct 473 ms 32672 KB Output is partially correct - 807874 bits used
10 Partially correct 534 ms 35224 KB Output is partially correct - 1266636 bits used