답안 #1011990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011990 2024-07-01T13:34:22 Z Unforgettablepl Shopping (JOI21_shopping) C++17
10 / 100
31 ms 1432 KB
#include "Anna.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int BLOCK_SIZE = 1382;


namespace {
int L, R;
vector<bool> buffer;
int ptr = 0;
bool read(){
    assert(ptr<buffer.size());
    return buffer[ptr++];
}

int get(int l,int r){
    vector<int> depth(2*BLOCK_SIZE+1);
    vector<int> p(2*BLOCK_SIZE+1);
    vector<int> actual(2*BLOCK_SIZE+1);
    int c = 0;
    int act = 0;
    int ll = -1,rr = -1;
    function<void(int,int)> readtree = [&](int par,int dep){
        p[c] = par;
        depth[c] = dep;
        int myc = c;
        c++;
        bool hasleft = read();
        bool hasright = read();
        if(hasleft)readtree(myc,dep+1);
        if(act==l)ll=myc;
        if(act==r)rr=myc;
        actual[myc] = act;
        act++;
        if(hasright)readtree(myc,dep+1);
    };
    readtree(-1,1);
    if(depth[ll]<depth[rr])swap(ll,rr);
    while(depth[ll]>depth[rr])ll = p[ll];
    while(true){
        if(ll==rr)return actual[ll];
        ll = p[ll];
        rr = p[rr];
    }
    assert(false);
}
}  // namespace

void InitA(int N, int L, int R) {
    ::L = L;
    ::R = R;
    int curr = 0;
    for(int i=0;i<724;i++){
        for(int j=i;j<724;j++){
            curr++;
            if(i==L/BLOCK_SIZE and j==R/BLOCK_SIZE)break;
        }
        if(i==L/BLOCK_SIZE)break;    
    }
    for(int bit=0;bit<18;bit++)SendA(curr&(1<<bit));
}

void ReceiveA(bool x) {
    buffer.emplace_back(x);
}

int Answer() {
    int middle_man = 0;
    for(int i=0;i<18;i++)if(read())middle_man|=(1<<i);
    int ll = L%BLOCK_SIZE;
    int rr = R%BLOCK_SIZE;
    if(L/BLOCK_SIZE!=R/BLOCK_SIZE)rr+=BLOCK_SIZE+1;
    int ans = get(ll,rr);
    if(ans==BLOCK_SIZE)return middle_man;
    if(ans<BLOCK_SIZE)return ans+(L/BLOCK_SIZE)*BLOCK_SIZE;
    if(ans>BLOCK_SIZE)return ans-BLOCK_SIZE-1+(R/BLOCK_SIZE)*BLOCK_SIZE;
    assert(false);
}
#include "Bruno.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int BLOCK_SIZE = 1382;

namespace {
vector<int32_t> P;
int N;
int cnt;
int num;
void generate(vector<pair<int,int>> arr){
    int n = arr.size();
    vector<pair<int,int>> tree(n+1,{-1,-1});
    vector<pair<int,int>> best(n);
    stack<pair<int,int>> s;
    s.emplace(0,-1);
    for(int i=0;i<n;i++){
        while(arr[i].second<s.top().first)s.pop();
        best[i] = s.top();
        s.emplace(arr[i].second,i);
    }
    while(!s.empty())s.pop();
    s.emplace(0,n);
    for(int i=n-1;i>=0;i--){
        while(arr[i].second<=s.top().first)s.pop();
        best[i] = max(best[i],s.top());
        if(best[i].second<i)tree[best[i].second].second=i;
        else tree[best[i].second].first=i;
        s.emplace(arr[i].second,i);
    }
    function<void(int)> dfs = [&](int x){
        if(x==-1)return;
        SendB(tree[x].first!=-1);
        SendB(tree[x].second!=-1);
        dfs(tree[x].first);
        dfs(tree[x].second);
    };
    dfs(tree[n].first);
}
}  // namespace

void InitB(int32_t N, std::vector<int32_t> P) {
    ::N = N;
    ::P = P;
}

void ReceiveB(bool y) {
    if(y)num|=1<<cnt;
    cnt++;
    if(cnt==18){
        int curr = 0;
        int l = -1,r = -1;
        for(int i=0;i<724;i++){
            for(int j=i;j<724;j++){
                if(++curr==num){
                    l = i;
                    r = j;
                }
            }
        }
        vector<pair<int,int>> arr;
        int t;
        for(int i=l*BLOCK_SIZE;i<(l+1)*BLOCK_SIZE;i++){
            if(i<N)arr.emplace_back(i,P[i]);
            else arr.emplace_back(i,1e10+(t++));
        }
        pair<int,int> currmin = {1e10+(t++),200000};
        for(int i=(l+1)*BLOCK_SIZE;i<r*BLOCK_SIZE;i++){
            currmin = min(currmin,{P[i],i});
        }
        for(int i=0;i<18;i++)SendB(currmin.second&(1<<i));
        arr.emplace_back(currmin.second,currmin.first);
        for(int i=r*BLOCK_SIZE;i<(r+1)*BLOCK_SIZE;i++){
            if(i<N)arr.emplace_back(i,P[i]);
            else arr.emplace_back(i,1e10+(t++));
        }
        generate(arr);
    }
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Anna.cpp:3:
Anna.cpp: In function 'bool {anonymous}::read()':
Anna.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     assert(ptr<buffer.size());
      |            ~~~^~~~~~~~~~~~~~

Bruno.cpp: In function 'void ReceiveB(bool)':
Bruno.cpp:67:41: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |             else arr.emplace_back(i,1e10+(t++));
      |                                     ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 992 KB Output is correct
2 Correct 27 ms 996 KB Output is correct
3 Correct 16 ms 920 KB Output is correct
4 Correct 24 ms 1012 KB Output is correct
5 Correct 26 ms 1168 KB Output is correct
6 Correct 24 ms 1004 KB Output is correct
7 Correct 31 ms 1000 KB Output is correct
8 Correct 23 ms 1000 KB Output is correct
9 Correct 25 ms 1168 KB Output is correct
10 Correct 18 ms 1000 KB Output is correct
11 Correct 24 ms 1172 KB Output is correct
12 Correct 27 ms 920 KB Output is correct
13 Correct 27 ms 920 KB Output is correct
14 Correct 25 ms 1000 KB Output is correct
15 Correct 23 ms 1244 KB Output is correct
16 Correct 20 ms 920 KB Output is correct
17 Correct 29 ms 1000 KB Output is correct
18 Correct 19 ms 1004 KB Output is correct
19 Correct 27 ms 1004 KB Output is correct
20 Correct 28 ms 1172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 992 KB Output is correct
2 Correct 27 ms 996 KB Output is correct
3 Correct 16 ms 920 KB Output is correct
4 Correct 24 ms 1012 KB Output is correct
5 Correct 26 ms 1168 KB Output is correct
6 Correct 24 ms 1004 KB Output is correct
7 Correct 31 ms 1000 KB Output is correct
8 Correct 23 ms 1000 KB Output is correct
9 Correct 25 ms 1168 KB Output is correct
10 Correct 18 ms 1000 KB Output is correct
11 Correct 24 ms 1172 KB Output is correct
12 Correct 27 ms 920 KB Output is correct
13 Correct 27 ms 920 KB Output is correct
14 Correct 25 ms 1000 KB Output is correct
15 Correct 23 ms 1244 KB Output is correct
16 Correct 20 ms 920 KB Output is correct
17 Correct 29 ms 1000 KB Output is correct
18 Correct 19 ms 1004 KB Output is correct
19 Correct 27 ms 1004 KB Output is correct
20 Correct 28 ms 1172 KB Output is correct
21 Correct 19 ms 1168 KB Output is correct
22 Correct 20 ms 1048 KB Output is correct
23 Correct 23 ms 992 KB Output is correct
24 Correct 26 ms 1040 KB Output is correct
25 Correct 27 ms 972 KB Output is correct
26 Correct 26 ms 1012 KB Output is correct
27 Correct 27 ms 1432 KB Output is correct
28 Correct 27 ms 1424 KB Output is correct
29 Correct 25 ms 1168 KB Output is correct
30 Correct 23 ms 1004 KB Output is correct
31 Correct 20 ms 1044 KB Output is correct
32 Correct 24 ms 964 KB Output is correct
33 Correct 16 ms 1004 KB Output is correct
34 Correct 22 ms 1008 KB Output is correct
35 Correct 22 ms 920 KB Output is correct
36 Correct 23 ms 1244 KB Output is correct
37 Correct 27 ms 996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 412 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -