Submission #1074414

# Submission time Handle Problem Language Result Execution time Memory
1074414 2024-08-25T10:23:39 Z TimDee Shopping (JOI21_shopping) C++17
1 / 100
31 ms 1380 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
int lx,rx;
int l,r;
int _n;
void InitA(int n, int l, int r) {
  _n=n;
  int k = 1384;
  lx = l/k;
  rx = r/k;
  ::l=l, ::r=r;
  int ans=0;
  int t = 723;
  for(int i=0; i<lx; ++i) ans+=t-i;
  for(int j=lx; j<rx; ++j) ans++;
  forn(i,18) SendA((ans>>i)&1);
}

int ai=-1;
int num=0;
int mn=-1;
vector<int> s;
void ReceiveA(bool ba) {
  int b = ba;
  if (ai<0 && rx<=lx+1) ai=0;
  if (ai<0) {
    num|=b<<(-ai-1);
    ++ai;
    if (ai==-21) {
      mn = num;
      num = 0;
      ai = 0;
    }
    return;
  }
  s.pb(b);
}

int Answer() {
  int k = 1384;
  vector<int> b; 
  if (lx==rx) {
    forn(i,min(k,_n-lx*k)) b.pb(lx*k+i);
  } else {
    forn(i,k) b.pb(lx*k+i);
    if (mn!=-1) b.pb(mn);
    forn(i,min(k,_n-rx*k)) b.pb(rx*k+i);
  }
  b.pb(1e9);
  int n=b.size();
  vector<int> st = {n-1};
  vector<int> l(n,-1), r(n,-1), p(n);
  int nxt=0;
  int last=-1;
  for(auto&x:s) {
    //cout<<x;
    if (x==0) {
      last=st.back();
      st.pop_back();
      continue;
    }
    p[nxt] = st.back();
    r[st.back()] = nxt;
    if (last!=-1) {
      l[nxt] = last;
      p[last] = nxt;
      last = -1;
    }
    st.pb(nxt);
    ++nxt;
  }
  //cout<<'\n';
  //forn(i,n) cout<<l[i]<<' '<<r[i]<<"  "<<p[i]<<'\n';
  //exit(0);
  int root = n-1;
  swap(l[root],r[root]);
  while (1) {
    if (::l<=b[root] && b[root]<=::r) return b[root];
    if (b[root] < ::l) {
      root = r[root];
    } else {
      root = l[root];
    }
  }
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
const int N=1e6+5;
int a[N];
int n;
void InitB(int n, vector<int> a) {
  forn(i,n) ::a[i]=a[i];
  ::n=n;
}

int rec=0;
int bi=0;
void ReceiveB(bool bx) {
  int x = bx;
  rec+=x<<bi;
  ++bi;
  if (bi==18) {
    int k = 1384;
    int t = 723;

    int lq=0, rq=0;
    for(int i=0; i<t; ++i) {
      if (rec>=t-i) ++lq;
      else break;
      rec-=t-i;
    }
    rq = lq+rec;
    assert(rq < t);

    int mn=-1;
    for(int i=(lq+1)*k; i<rq*k; ++i) {
      if (mn==-1) mn=i;
      if (a[i]<a[mn]) mn=i;
    }
    if (mn!=-1) {
      forn(i,20) SendB((mn>>i)&1);
    }
    vector<int> st={-N};
    for(int i=lq*k; i<min(lq*k+k,n); ++i) {
      while (a[i]<st.back()) {
        SendB(0);
        st.pop_back();
      }
      SendB(1);
      st.pb(a[i]);
    }
    if (mn!=-1) {
      while (a[mn]<st.back()) {
        SendB(0);
        st.pop_back();
      }
      SendB(1);
      st.pb(a[mn]);
    }
    if (lq!=rq) for(int i=rq*k; i<min(rq*k+k,n); ++i) {
      while (a[i]<st.back()) {
        SendB(0);
        st.pop_back();
      }
      SendB(1);
      st.pb(a[i]);
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 2 ms 664 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 1 ms 664 KB Output is correct
5 Correct 1 ms 664 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 12 ms 1380 KB Output is correct
8 Correct 9 ms 664 KB Output is correct
9 Correct 9 ms 664 KB Output is correct
10 Correct 9 ms 664 KB Output is correct
11 Correct 9 ms 664 KB Output is correct
12 Correct 5 ms 664 KB Output is correct
13 Correct 9 ms 760 KB Output is correct
14 Correct 9 ms 664 KB Output is correct
15 Correct 9 ms 1040 KB Output is correct
16 Correct 9 ms 932 KB Output is correct
17 Correct 9 ms 684 KB Output is correct
18 Correct 9 ms 676 KB Output is correct
19 Correct 9 ms 676 KB Output is correct
20 Correct 9 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 2 ms 664 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 1 ms 664 KB Output is correct
5 Correct 1 ms 664 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 12 ms 1380 KB Output is correct
8 Correct 9 ms 664 KB Output is correct
9 Correct 9 ms 664 KB Output is correct
10 Correct 9 ms 664 KB Output is correct
11 Correct 9 ms 664 KB Output is correct
12 Correct 5 ms 664 KB Output is correct
13 Correct 9 ms 760 KB Output is correct
14 Correct 9 ms 664 KB Output is correct
15 Correct 9 ms 1040 KB Output is correct
16 Correct 9 ms 932 KB Output is correct
17 Correct 9 ms 684 KB Output is correct
18 Correct 9 ms 676 KB Output is correct
19 Correct 9 ms 676 KB Output is correct
20 Correct 9 ms 668 KB Output is correct
21 Runtime error 31 ms 688 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -