1. Trang chủ
  2. » Giáo án - Bài giảng

Đáp án Đề thi Tin QT (IOI) 2001

7 243 2
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 66 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In this simple solution, updates are done in constant time O1 and queries in a time proportional to the area of the query worst case OS^2.. This gives rise to solutions with worst case O

Trang 1

Some information about task MOBILES

This is an asymmetrically reactive task, in the sense that the inputs

to the competitor program do not depend on its previous outputs, in a relevant way Note that the competitor program's output is uniquely defined by its preceding input The task requires the competitor to develop an on-line algorithm, rather than an off-line algorithm If all the input would be available in an input file (batch type), then also

"future" updates and queries would be available (off-line), changing the nature of the challenge

It is very easy to write a program that maintains the count for each square in a SxS table (4MB worst case), and that answers the queries correctly by adding the appropriate counts In this simple solution, updates are done in constant time (O(1)) and queries in a time

proportional to the area of the query (worst case O(S^2)) However, the time limit and allowed matrix sizes require a better solution to obtain a full score

There are various ways to "improve" the simple solution by maintaining sums of counts over rectangles, e.g., with common upper left-hand

corners

(using only one SxS table) Combining four such sums provides the answer

to an arbitrary query This gives rise to solutions with worst

case O(S^2) update time and O(1) query time

By maintaining the sums of counts over, e.g., all vertical strips with common upper end point (still using one SxS table), one gets a solution with worst case O(S) update and O(S) query

There are various ways to improve these solutions by using more advanced data structures A good choice is a binary indexed tree to maintain cumulative counts for a one-dimensional array, with worst case O(log S) update and query Using this in both dimensions (tree of trees), yields solutions with worst case O((log S)^2) time for both update and query The 5MB limit on memory also forces the competitor to limit the data structure essentially to one SxS table of sums in order to solve the largest cases This poses an additional challenge

The 20 test cases were designed to probe the solution for correctness and for efficiency, both in time and in memory

Case S N Comment

-

1 1 20 Pairs of random update followed by random query

2 33 3089 2000 random updates followed by all possible 1x1 queries

3 7 833 All updates (i,j,7i+j) followed by all possible queries

4 128 10000 Random mix of random updates and random queries (ratio 1:2)

5 210 25000 Same as 4

6 250 25000 Same as 4

7 300 30000 Same as 4

8 365 40000 Same as 4

Trang 2

9 441 55000 Random mix of random updates and random big* queries (1:2)

10 463 55000 Same as 9

11 474 55000 Same as 9

12 482 55000 Same as 9

13 496 60000 Same as 9

14 503 60000 Same as 9

15 509 60000 Same as 9

16 512 60000 Same as 9

17 614 60000 Same as 9

18 819 60000 Same as 9

19 1024 60000 Same as 9

20 1024 60000 Same as 9

where

S = Size of matrix

N = Total number of operations

* = big query involves area of at least S/2 x S/2 squares

random = random per competitor, but the same for all competitors

Correct programs involving operations with worst case time O(S^2)

can pass cases 1 to 4 (20 points)

Correct programs involving operations with worst case time O(S)

can pass cases 1 to 8 (40 points)

Correct programs involving operations with worst case time O((log S)^2) and non-optimized memory usage can pass cases 1 to 16 (80 points)

Correct programs involving operations with worst case time O((log S)^2) and optimized memory usage can pass all cases (100 points)

Programs that use "trees" in only one dimension can score better

than the simple programs

NOTE: The input data for each test case is generated inside the checker, rather than read from an input file

2/Some information about task IOIWARI

Various parameters of the game (the number of the pits, the number and distribution of the beads, and especially the rule for moves) have been tuned

to satisfy the following requirements:

- the game is always winnable by the first player

but not easy to win in most cases

- some game instances are winnable by the first player playing by a simple

(greedy) strategy

- efficient solution possible with reasonable resource limitations (memory and CPU time)

- draw is possible

- the nummber of different game instances is sufficiently large for testing

TEST

The opponent program plays to achive maximum score differece for the second

Trang 3

There are 51 different initial game positions modulo rotation

Score differeces (Bank1-Bank2)

B : Initial Game Position

O : Optimal score difference for the first player

G1: Best score difference when first player plays according to a one-step

look-ahead greedy strategy

G2: Best score difference when first player plays according to a two-step

look-ahead greedy strategy

R : Score difference when first player plays by random choice

Case B O G1 G2 R

-

1 4 4 4 2 2 2 2: 4 -6 -4 -2

2 3 4 4 3 2 2 2: 4 -6 -2 -10

3 3 4 3 4 2 2 2: 2 -8 -10 -12

4 3 3 4 4 2 2 2: 4 -2 -4 -8

5 4 4 3 2 3 2 2: 6 0 -8 -8

6 3 4 4 2 3 2 2: 2 -2 -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3 2 3 2: 2 2 -2 0

4 3 2 4 2 3 2: 2 0 -2 -4

3 4 2 4 2 3 2: 2 2 -2 -8

4 2 3 4 2 3 2: 6 6 -4 -4

3 3 3 4 2 3 2: 6 2 -4 -8

3 3 4 2 3 3 2: 4 2 -2 -6

3 3 3 3 3 3 2: 2 2 -2 2

The dialog between your program and the opponent program is recorded in the

file ioiwariX.report for test case X

3/Some information about task TWOFIVE

There are over 700 million valid words Therfore, in computing the

number that corresponds to a word, we must avoid explicitly counting every lexicographically preceding word The key observation is that the number of valid words consistent within an assignment of the first

k letters of the alphabet (i.e A letter[k]) to a set of locations depends on the locations occupied by these letters, but not on which letter is assigned to each location For example, the number of valid words consistent with the letters A G in either of the configurations below is the same:

Configuration 1: A B E F

C G D Configuration 2:

A D F G

B E C This is enough to permit a dynammic programming approach to succeed in the permitted time Indeed, we have an "untuned" 8 millisecond

solution

20 test cases were given as 10 pairs The first of each pair gives a word, from which we are to compute the number, while the second asks for the inverse computation As a consequence, brute forse does work for small numbers and their inverses

The data consisted of:

3 and its inverse, "ABCDEFGHIJKLMNOPQRSVTUWXY";

20 and its inverse;

1 000 000 and its inverse;

the maximum number (701149020) and its inverse;

and seven other essentially random nine digit values

Case T N

-

1 W 20

2 N 20

3 W 3

4 N 3

Trang 5

5 W 701149020 Last word in the lexicon

6 N 701149020

7 W 1000000

8 N 1000000

9 W 350574511

10 N 350574511

11 W 106407948

12 N 106407948

13 W 100000000

14 N 100000000

15 W 299925684

16 N 299925684

17 W 699509817

18 N 699509817

19 W 660689109

20 N 660689109

where

T = kind of case (W or N)

N = ordinal number

4/Some information about task SCORE

In this task, the important thing to discover somehow, is that

removal of the starting position yields a directed acyclic graph (DAG)

A depth-first search (DFS) rooted at the starting position yields a traversal tree whose back-edges all go to the root Using a minimax evaluation on that tree gives an optimal strategy in a time linear

in the number of edges of the game graph

The 20 test cases were designed by varying the path lengths, node

values,

and number of edges, such that various non-optimal strategies can be distinguished The test data was evaluated against random strategies, the 1-step look-ahead greedy strategy, the 2-step look-ahead greedy strategy, and exhaustive game-state evaluation

5/Some information about task DOUBLE

A simple approach to solving this task is an exhaustive search over the combined key spaces:

for each key k1

for each key k2

if E(E(p, k1), k2) = c2

exit with k1, k2

This requires in the worst case (20-bit keys) about 2^20 * 2^20 * 2 = 2^41

encryptions Doing an optimistic 10^6 encryptions per second it would still take more than 25 days (It can be halved by taking E(p, k1) outside the inner loop.)

However, double encryption, as applied in this task, provides much less extra security than may at first seem to be the case If the key length

is n bits for single encryption, then an exhaustive search goes through all possible 2^n keys Double encryption with two independent n-bit keys

may seem to correspond to encryption with a single 2n-bit key But

Trang 6

the so-called "meet-in-the-middle attack" shows that it is actually no stronger than a single (n+1)-bit key (For that reason, in practice, triple encryption is used for improving security.)

The meet-in-the-middle attack works as follows The given plain

text p is encrypted with all possible 2^n keys and the results are

stored (one way or another) in a table Next, the given

double-encrypted

ciphertext c2 is _decrypted_ with all possible 2^n keys, and each result

is checked against the table for a "collision" Such a collision

reveals a "double key" used for encryption

The table is best set up as a hashed dictionary, to make both store and retrieve operations fast The dictionary size needs to allow for more entries than keys to avoid too many hash collissions Sizing the dictionary to twice the number of keys, and storing a 20-bit key and

a 128-bit encrypted message together in 20 bytes, requires 2^21 * 20 = 40MB for the dictionary This size can be reduced to 8 MB by not

storing

the message and recomputing it from the stored key

The ten cases have the following characteristics:

Case s T k1 k2 Comments

- -

1 1 P A 7 This case is the same as the example

2 1 R C 5 Can be solved manually with the tool

3 2 P A7 6E Can be solved by exhaustive search

4 2 C E1 8A Can be solved by exhaustive search

5 4 R A39E B760

6 4 R 893D F66B

7 4 R 9325 0000 Extreme key at one end of key space

8 5 C CB053 7F0F9

9 5 P A7000 6E000 Same answer as case 3

10 5 P 59D04 FFFFF Extreme key at other end of key space where

s = number of relevant hexadecimal key digits (task input)

T = type of plaintext/ciphertext:

P for structured plaintext (random-looking ciphertext)

C for structured ciphertext (random-looking plaintext)

R for random plaintext/ciphertext

k1 = first key (task output)

k2 = second key (task output)

NOTES

All answers can easily be verified by the interactive tool that was provided

All possible key digits 0 F appear in the keys, including duplicates Structure in the plaintext or ciphertext cannot be exploited

Cases with s=4 can be solved by exhaustive search, but each takes more than one hour Because these three cases have the same plaintext, they can be attacked together with exhaustive search, to solve three cases for the price of one case plus a little bit Even a straightforward implementation of the meet-in-the-middle-attack works in seconds

Trang 7

Cases with s=5 require a good implementation of the meet-in-the-middle search They cannot be solved by exhaustive search within the five hours of the competition However, case 9 has the same solution

as case 3! This can be recognized by inspecting the input files

The AES library allows for roughly 0.5e6 encryptions per second

Decryption is about a factor two slower than encryption

6/Some information about task DEPOT

The 25 test cases have the following characteristics

Case N Shape P Note

-

1 3 3 1 1, 2, 3, 4

2 3 1 1 1 1 1, 2, 3, 4

3 3 2 1 2 1, 2, 3, 4

4 4 2 2 2 2, 3, 4

5 5 2 1 1 1 4 2, 3, 4

6 6 3 2 1 16 2, 3, 4 (largest output for N=6)

7 7 3 2 1 1 35 2, 3, 4 (largest output for N=7)

8 7 2 2 2 1 14 2, 3, 4

9 8 4 3 1 70 2?, 3, 4

10 8 4 2 1 1 90 2?, 3, 4 (largest output for N=8)

11 8 3 2 2 1 70 2?, 3, 4

12 9 3 2 2 2 84 3, 4

13 9 4 3 2 168 3, 4

14 9 4 2 2 1 216 3, 4 (largest output for N=9)

15 10 4 2 2 2 300 3, 4

16 10 4 3 2 1 768 3, 4 (largest output for N=10)

17 10 5 2 2 1 525 3, 4

18 11 6 5 132 3, 4

19 11 5 3 2 1 2310 3, 4 (largest output for N=11)

20 12 5 4 2 1 5775 3, 4

21 12 5 3 2 1 1 7700 3, 4 (largest output for N=12)

22 13 8 1 1 1 1 1 792 3, 4

23 13 2 2 2 2 2 2 1 429 3, 4

24 13 5 3 2 2 1 21450 3, 4 (largest output for N=13)

25 13 5 4 2 1 1 21450 3, 4 (largest output for N=13)

where

N = number of containers in depot (from input)

Shape = vector of subsequent row lengths (sum = N; input)

P = number of possible orders

Note = 1, solvable by pre-tabulating small cases

2, solvable by enumerating permutations, building depots, and test

3, solvable by straightforward top-down backtracking

4, solvable by recursively breaking down the depot in reverse order

In general, the number of possibilities goes up with N as N!/sqrt(N) There also exist fast heuristic approaches that will find some but not all

possibilities, and that may get a partial score

Ngày đăng: 30/06/2014, 02:00

TỪ KHÓA LIÊN QUAN

w