Submission #24466

# Submission time Handle Problem Language Result Execution time Memory
24466 2017-06-09T08:57:55 Z gs14004 Last supper (IOI12_supper) C++11
100 / 100
241 ms 10600 KB
#include "advisor.h"
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int,int> pi;
 
set<pi> s;
vector<pi> nexts;
int query[100005];
int is_in[100005];
 
int getnxt(int val, int time){
    auto t = upper_bound(nexts.begin(), nexts.end(), pi(val, time));
    if(t->first != val) return 1e9;
    return t->second;
}
 
bool PopPrevRequest[100005];
bool PopK[100005];
 
void ComputeAdvice(int *C, int N, int K, int M) {
    for(int i=0; i<N; i++){
        nexts.push_back(pi(C[i], i));
    }
    sort(nexts.begin(), nexts.end());
    for(int i=0; i<K; i++){
        s.insert(pi(getnxt(i, -1), i));
        is_in[i] = 1;
    }
    for(int i=0; i<N; i++){
        query[i] = N;
        if(is_in[C[i]]){
            if(s.find(pi(i, C[i])) != s.end()) s.erase(pi(i, C[i]));
            s.insert(pi(getnxt(C[i], i), C[i]));   
        }
        else{
            auto t = --s.end();
            query[i] = t->second;
            is_in[t->second] = 0;
            s.erase(t);
            s.insert(pi(getnxt(C[i], i), C[i]));
            is_in[C[i]] = 1;
        }
    }
    for(int i=0; i<N; i++){
        if(query[i] != N){
            auto t = lower_bound(nexts.begin(), nexts.end(), pi(query[i], i));
            if(t == nexts.begin() || (t-1)->first != query[i]){
                PopK[query[i]] = 1;
            }
            else{
                t--;
                PopPrevRequest[t->second] = 1;
            }
            // investigate last use of pop query
        }
    }
    for(int i=0; i<N; i++){
        WriteAdvice(PopPrevRequest[i]);
    }
    for(int i=0; i<K; i++){
        WriteAdvice(PopK[i]);
    }
}
#include "assistant.h"
#include <set>
using namespace std;
set<int> pops, scaffold;
 
void Assist(unsigned char *A, int N, int K, int R) {
    int prevReq = -1;
    for(int i=0; i<K; i++){
        scaffold.insert(i);
        if(A[i+N]) pops.insert(i);
    }
    for(int i=0; i<N; i++){
        int curReq = GetRequest();
        if(scaffold.find(curReq) == scaffold.end()){
            PutBack(*pops.begin());
            scaffold.erase(*pops.begin());
            pops.erase(pops.begin());
            scaffold.insert(curReq);
        }
        if(A[i]){
            pops.insert(curReq);
        }
    }
}

Compilation message

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:7:9: warning: unused variable 'prevReq' [-Wunused-variable]
     int prevReq = -1;
         ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 752 KB Output is correct
2 Correct 4 ms 924 KB Output is correct
3 Correct 5 ms 1064 KB Output is correct
4 Correct 7 ms 1128 KB Output is correct
5 Correct 13 ms 1416 KB Output is correct
6 Correct 9 ms 1704 KB Output is correct
7 Correct 9 ms 1704 KB Output is correct
8 Correct 11 ms 1736 KB Output is correct
9 Correct 15 ms 1768 KB Output is correct
10 Correct 13 ms 1768 KB Output is correct
11 Correct 12 ms 1768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2144 KB Output is correct
2 Correct 83 ms 4688 KB Output is correct
3 Correct 223 ms 10600 KB Output is correct
4 Correct 173 ms 10600 KB Output is correct
5 Correct 175 ms 10600 KB Output is correct
6 Correct 185 ms 10600 KB Output is correct
7 Correct 203 ms 10600 KB Output is correct
8 Correct 166 ms 10600 KB Output is correct
9 Correct 145 ms 10600 KB Output is correct
10 Correct 234 ms 10600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 10600 KB Output is correct
2 Correct 206 ms 10600 KB Output is correct
3 Correct 212 ms 10600 KB Output is correct
4 Correct 205 ms 10600 KB Output is correct
5 Correct 197 ms 10600 KB Output is correct
6 Correct 236 ms 10600 KB Output is correct
7 Correct 203 ms 10600 KB Output is correct
8 Correct 191 ms 10600 KB Output is correct
9 Correct 180 ms 10600 KB Output is correct
10 Correct 241 ms 10600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10600 KB Output is correct
2 Correct 12 ms 10600 KB Output is correct
3 Correct 10 ms 10600 KB Output is correct
4 Correct 13 ms 10600 KB Output is correct
5 Correct 9 ms 10600 KB Output is correct
6 Correct 9 ms 10600 KB Output is correct
7 Correct 12 ms 10600 KB Output is correct
8 Correct 11 ms 10600 KB Output is correct
9 Correct 12 ms 10600 KB Output is correct
10 Correct 12 ms 10600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 10600 KB Output is correct - 120000 bits used
2 Correct 227 ms 10600 KB Output is correct - 122000 bits used
3 Correct 212 ms 10600 KB Output is correct - 125000 bits used
4 Correct 239 ms 10600 KB Output is correct - 125000 bits used
5 Correct 220 ms 10600 KB Output is correct - 125000 bits used
6 Correct 232 ms 10600 KB Output is correct - 125000 bits used
7 Correct 222 ms 10600 KB Output is correct - 124828 bits used
8 Correct 212 ms 10600 KB Output is correct - 124910 bits used
9 Correct 208 ms 10600 KB Output is correct - 125000 bits used
10 Correct 191 ms 10600 KB Output is correct - 125000 bits used