#P5458. [BJOI2016] 水晶

    ID: 6196 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>图论2016各省省选网络流北京O2优化

[BJOI2016] 水晶

Background

Do not panic, none of today’s problems were made by Xiaoqiang.

—A work poured with countless efforts, yet now he has to destroy it with his own hands. It is hard to understand how he feels.

—There is no other choice. If the energy resonance is not removed...

Looking at the crystals already planted with explosives, 02 put down the telescope and looked at the resonance analysis report in his hand.

Some crystals will still survive... maybe.

Problem Description

The map consists of densely tiled hexagonal cells, and each cell is adjacent to six other cells.

For convenience, we use coordinates (x,y,z)(x,y,z) to describe the position of a cell: starting from the origin, walk several steps along the xx, yy, and zz directions as shown in the figure to reach that cell.

It is possible that two coordinates describe the same cell. For example, (1,1,1)(1,1,1) and (0,0,0)(0,0,0) both describe the origin.

Clearly, cell (x,y,z)(x,y,z) is adjacent to (x+1,y,z)(x+1,y,z), (x1,y,z)(x-1,y,z), (x,y+1,z)(x,y+1,z), (x,y1,z)(x,y-1,z), (x,y,z+1)(x,y,z+1), and (x,y,z1)(x,y,z-1).

There are NN crystals located in the cells of the map. The ii-th crystal is in the cell described by coordinates (xi,yi,zi)(x_i, y_i, z_i) and has value cic_i. A single cell may contain multiple crystals.

On the map, some cells have energy sources installed. As shown below, any cell described by coordinates whose x+y+zx+y+z is a multiple of 33 has an energy source installed.

The value of crystals in a cell with an energy source increases by an additional 10%10\%. If the cells containing three crystals satisfy certain patterns, they will trigger resonance.

There are two types of resonance: aa resonance and bb resonance.

aa resonance: If the cells containing three crystals form a triangle such that every pair of cells is adjacent, then an aa resonance is triggered.

In the figure, each triangle means that if each of the three cells contains one crystal, they will trigger one aa resonance.

bb resonance: If the cells containing three crystals are arranged in a straight line segment of length 22 such that consecutive cells are adjacent, and the middle cell has an energy source, then a bb resonance is triggered.

In the figure, the pink segments indicate that if each of the three cells contains one crystal, they will trigger a bb resonance. The black segments indicate that even if these three cells contain crystals, they will not trigger a bb resonance.

Now you need to blow up some crystals so that no resonance occurs, and under this condition, maximize the total value of the remaining crystals.

Input Format

The first line contains a positive integer NN, the number of crystals.
The next NN lines each contain four integers separated by spaces: xi,yi,zi,cix_i,y_i,z_i,c_i, describing the position and value of a crystal.
Different crystals may share the same position.

Output Format

Output one real number in a single line: the total value of the remaining crystals, rounded to 11 decimal place.

4
0 0 0 11
1 0 0 5
0 1 0 7
0 0 -1 13
25.1

Hint

[Sample 11 Explanation]

Four crystals form a diamond shape. There is no bb resonance, and there are 22 occurrences of aa resonance: the triangles formed by crystals 1,2,41,2,4 and by crystals 1,3,41,3,4.

Therefore, to eliminate the two aa resonances, there are 33 possible plans:

  1. Blow up crystal 11, keep crystals 2,3,42,3,4, total remaining value 5+7+13=255+7+13=25.
  2. Blow up crystal 44, keep crystals 1,2,31,2,3, total remaining value 11×(1+10%)+5+7=24.111 \times(1+10\%)+5+7=24.1.
  3. Blow up crystals 2,32,3, keep crystals 1,41,4, total remaining value 11×(1+10%)+13=25.111 \times (1+10\%)+13=25.1.

So we choose the third plan, and the maximum total remaining value is 25.125.1.

[Constraints]

1N500001\le N \le 50000
1ci10001\le c_i \le 1000
1000xi,yi,zi1000-1000 \le x_i,y_i,z_i \le 1000

Translated by ChatGPT 5