CF715D.Create a Maze

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n×mn×m rooms, and the rooms are arranged in nn rows (numbered from the top to the bottom starting from 11 ) and mm columns (numbered from the left to the right starting from 11 ). The room in the ii -th row and jj -th column is denoted by (i,j)(i,j) . A player starts in the room (1,1)(1,1) and wants to reach the room (n,m)(n,m) .

Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i,j)(i,j) and (i,j+1)(i,j+1) is locked, then we can't go from (i,j)(i,j) to (i,j+1)(i,j+1) . Also, one can only travel between the rooms downwards (from the room (i,j)(i,j) to the room (i+1,j)(i+1,j) ) or rightwards (from the room (i,j)(i,j) to the room (i,j+1)(i,j+1) ) provided the corresponding door is not locked.

This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.ZS the Coder considers a maze to have difficulty xx if there is exactly xx ways of travelling from the room (1,1)(1,1) to the room (n,m)(n,m) . Two ways are considered different if they differ by the sequence of rooms visited while travelling.

Your task is to create a maze such that its difficulty is exactly equal to TT . In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?

输入格式

The first and only line of the input contains a single integer TT ( 1<=T<=10181<=T<=10^{18} ), the difficulty of the required maze.

输出格式

The first line should contain two integers nn and mm ( 1<=n,m<=501<=n,m<=50 ) — the number of rows and columns of the maze respectively.

The next line should contain a single integer kk ( 0<=k<=3000<=k<=300 ) — the number of locked doors in the maze.

Then, kk lines describing locked doors should follow. Each of them should contain four integers, x1,y1,x2,y2x_{1},y_{1},x_{2},y_{2} . This means that the door connecting room (x1,y1)(x_{1},y_{1}) and room (x2,y2)(x_{2},y_{2}) is locked. Note that room (x2,y2)(x_{2},y_{2}) should be adjacent either to the right or to the bottom of (x1,y1)(x_{1},y_{1}) , i.e. x2+y2x_{2}+y_{2} should be equal to x1+y1+1x_{1}+y_{1}+1 . There should not be a locked door that appears twice in the list.

It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

输入输出样例

  • 输入#1

    3
    

    输出#1

    3 2
    0
    
  • 输入#2

    4
    

    输出#2

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

说明/提示

Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.

In the first sample case:

In the second sample case:

首页