답안 #118619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118619 2019-06-19T09:57:09 Z Plurm 최후의 만찬 (IOI12_supper) C++11
0 / 100
534 ms 34440 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;
        }
    }
    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;
            f[INF] = 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;
                f[INF] = 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 < 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);
    }
    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:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < raw.size(); i++){
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10240 KB Output is correct
2 Incorrect 8 ms 9984 KB Output isn't correct - not an optimal way
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 12288 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 336 ms 28600 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 10752 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 422 ms 32504 KB Output isn't correct - not an optimal way
2 Incorrect 534 ms 32584 KB Output isn't correct - not an optimal way
3 Incorrect 468 ms 32728 KB Output isn't correct - not an optimal way
4 Incorrect 450 ms 32752 KB Output isn't correct - not an optimal way
5 Incorrect 418 ms 32752 KB Output isn't correct - not an optimal way
6 Incorrect 428 ms 32736 KB Output isn't correct - not an optimal way
7 Incorrect 417 ms 32584 KB Output isn't correct - not an optimal way
8 Incorrect 421 ms 32712 KB Output isn't correct - not an optimal way
9 Incorrect 432 ms 32552 KB Output isn't correct - not an optimal way
10 Incorrect 449 ms 34440 KB Output isn't correct - not an optimal way