By Shayan

Before stream
02:50:37

# | User | Rating |
---|---|---|

1 | tourist | 3690 |

2 | jiangly | 3647 |

3 | Benq | 3581 |

4 | orzdevinwang | 3570 |

5 | Geothermal | 3569 |

5 | cnnfls_csy | 3569 |

7 | Radewoosh | 3509 |

8 | ecnerwala | 3486 |

9 | jqdai0815 | 3474 |

10 | gyh20 | 3447 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | awoo | 164 |

3 | adamant | 163 |

4 | TheScrasse | 159 |

5 | nor | 157 |

6 | maroonrk | 155 |

7 | -is-this-fft- | 152 |

8 | Petr | 146 |

8 | orz | 146 |

10 | BledDest | 145 |

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/18/2024 16:09:23 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Auto comment: topic has been translated by Barsic (original revision, translated revision, compare)Did you read Problems and Solutions section at official website?

Thank you. I read analysis. And want to solve problem with such algorithm :

1) make list of comparison ( first, second ) where we put pair ( first, second ) when we know that first < second.

2) look all permutations of { 1, 2, 3, 4, 5, 6 } ( with next permutation() in C++ ).

2.1) if current permutation does not satisfy to list of comparison then look next permutation.

2.2) if current permutation are satisfy to list of comparison then in this permutation find pair P[i] and P[i + 1] which not situated in list of comparison, compare them and add the result to list of comparison.

We continue this procedure untill permutations are not finished or we not compare more than 6 founded pairs ( P[i], P[i + 1]). At the end we found right permutation.

In this problem T <= 18 and all permutation of { 1, 2, 3, 4, 5, 6 } = 6! = 720 then O(18 * 780) = O (12960).

No more than 1 second. But I got TL. Here is my code. Can you say where my mistake or show another solution with realization?

Thank you.

Hi, it seems to me, that your code runs into an infinite loop, for example when the output would be {1,2,3,4,5,6}, since at the start of the "while(1==1)" loop k==0, and you only increase k 5 times (in the inner loop after if(t==1), for i=0..4), so k will remain 5 throughout the execution, therefore you don't execute the break; command (if(k>6) break;). On the other hand since t always remains 1, you don't execute the other break; command either (if((t==0) && ...) break;), so you never jump out of the while loop.

I hope, I am not missing anything. :)