#13010. [BalkanOI 2011] cmp

    ID: 13010 传统题 1000ms 17MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P67522011交互题Special Judge进制其它技巧BalkanOI(巴尔干半岛)

[BalkanOI 2011] cmp

[BalkanOI 2011] cmp

题目描述

You must design an algorithm for an ancient computer whose memory is just an array of $10240$ bits.The memory is initialized to zero, after which you may write and read a single bit at a time.

You must implement two operations on this computer:

remember⁡(a)\operatorname{remember}(a): aa is an integer between 00 and 40954095

  • The implementation of this operation may call:
    • bit_set⁡(address)\operatorname{bit\_set}(address):     \ \ \ \ addressaddress is an integer between 11 and 1024010240
    • The memory bit at position address will be set to 11

compare⁡(b)\operatorname{compare}(b): bb is an integer between 00 and 40954095

  • if b<ab < a, it should return −1-1
  • if b=ab = a, it should return 00
  • if b>ab > a, it should return 11
  • The implementation of this operation may call:
    • bit_get⁡(address)\operatorname{bit\_get}(address) Returns the memory bit at position addressaddress: 11 if it was set through bit_set⁡()\operatorname{bit\_set}() during the remember⁡(a)\operatorname{remember}(a) operation, and 00 otherwise.

Implement remember⁡()\operatorname{remember}() and compare⁡()\operatorname{compare}() to minimize the total number of memory accesses (bit_set⁡()\operatorname{bit\_set}() and bit_get⁡()\operatorname{bit\_get}()) in the worst-case for all possible values of aa and bb.

Your solution will be evaluated exhaustively:

define AllMemory = array [0..4095][1..10240] of bits
set AllMemory to zeros
for a = 0..4095:
    define bit_set(address): AllMemory[a][address] = 1
    remember(a)
let maxA= the maximum number of bit_set() calls executed for any a
for (a,b) ∈ {0..4095}×{0..4095} in random order (i.e. all valid pairs (a,b) are considered, in some random order)
    define bit_get(address): return AllMemory[a][address]
    answer =compare(b)
    if answer for comparing a and b is incorrect : your score = 0; exit
let maxB = the maximum number of bit_get() calls executed for any (a,b) pair
T=maxA + maxB
If (T>20): your score = 0; exit
else your score = 1 + 9 * (21– T); exit

输入格式

(暂无输入格式说明)

输出格式

(暂无输出格式说明)

提示

### Description of implementation

Actually many things are here. BUT, If YOU ARE GOING TO SUBMIT ON LUOGU, You Should Use C++, YOUR CODE MUSTN'T INCLUDE cmp.h.

Here is an example code to submit on Luogu.

#include<bits/stdc++.h>
using namespace std;
// Your codes here
extern"C" void bit_set(int);
extern"C" int bit_get(int);
extern"C" void remember(int a){
    // Your codes here
}
extern"C" int compare(int b){
    // Your codes here
}

Constraints

  • You may be disqualified for any attempt to interact with the memory of our grading code.
  • If your solution does not obey the protocol defined above (e.g. calling bit_set⁡()\operatorname{bit\_set}() during compare⁡()\operatorname{compare}() or with an invalid address), you will receive zero points.
  • Time limit: your implementation must execute 40964096 calls to remember⁡()\operatorname{remember}() and 4096×40964096\times 4096 calls to compare⁡()\operatorname{compare}() in under 1010 seconds.

From Balkan Olympiad in Informatics 2011 Day 2 T1 cmp. 标签: P6752|2011|交互题|Special Judge|进制|其它技巧|BalkanOI(巴尔干半岛)

来源

P6752|[BalkanOI 2011] cmp