Matistjati
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Coin stacks Intuitively, the only way we can lose is we end up with a single stack that's very large. So why don't we always pick the two largest stacks? This turns out to be optimal. So we can simply simulate this, and print the output if it's valid, otherwise print no. A very evil edge case is that the input can have coin stacks with no coins in them, which we must simply discard. [Implementation](https://gist.github.com/Matistjati/d1da4fb17ee3f3b4a60fd695463415a3) # Cash transport The main insight in this problem is that transports get more valuable over time, so we want to rob the $K$ most valuable of them. The only problem is then To choose the $K$ most valuable without double counting. The way i implemented it is that each bank stores a list of all transactions that has gone into it. Once a cash van transports money from bank a to bank b, bank a's transactions is emptied, and converted into a single transaction for bank b. At the end, we just take the $K$ most valuable of these. We also need to be careful so we don't accidentally rob banks (money that has never been moved) [Implementation](https://gist.github.com/Matistjati/1bf762c8c93711ccd967d36f7f955310) # Find the graph Hasty editorial First, for every node $u$, query the following sets: $\{u\}$ and the rest of the graph. This gives us the degree of every node. If we query $\{v,u\}$ and the rest of the graph, the answer will be equal to $deg[u]+deg[v]$ if there is no edge between them. If it is not equal to that, there is an edge. So in one query, we can find whether some edge exists. As we can make many queries, we can simply query every pair of vertices. # Sharing candies Hasty editorial Let $p[i]=c_0+c_1+\dots+c_{i-1}$ (mod n). Compute all $p[i]$. If any $p[i]=0$, we are done. Otherwise, it turns out that there is always a contiguous interval with sum divisble by $n$. Consider some $i$. All intervals ending with $i$ can be expressed as $p[i]-p[j]$ for some $j<i$. So we want to check if there is some $j$ s.t. $p[i]-p[j]=0 \Rightarrow p[i]=p[j]$. So we can simply keep track of possible $p[j]$, and if any $p[i]$ is possible, we are done. In fact, by the pidgeonhole principle plus the fact that if any $p[i]$ is 0 we are done, this must always create a valid sum. # Red/blue spanning tree Hasty editorial https://codeforces.com/blog/entry/94709 # Football If you are very clever, there's a quite ingenious bitset solution. However, there is a simpler one. The main insight is that "every boy faces every other boy atleast once" is equivalent to "there is no pair of boys that are on the same side every time". From this, we simply need a nice encoding describing the sides that each boy has been on, and then check if there are any duplicates. One natural such encoding is that for the i:th match, the i:th bit is on if they are on the left, and 0 if not. We can then just throw all of these into a set and check if there any duplicates. Voila! Implementation note: to set the i'th bit, we do ```c++ x |= 1LL << i; ``` Note the 1LL. If we just do 1, that's an int, and will overflow for i>31. [Implementation](https://gist.github.com/Matistjati/a70114d7f946f8b4cb69187e21a27945) # RúnaHeimur First off, note that we have *a lot* of moves at our disposal. In the worst case, the board is $10 \times 10=100$. If we move each block across the whole board, it would move 100 spaces. So in this worst case, we make $100^2=10000$ moves. So as long as we use a reasonable strategy, the number of moves is not a concern. The first insight is that we can solve the top layer, and then completely ignore it, reducing the puzzle by 1 row. This can always be done "easily" as long as we have at least 4 rows left. By symmetry, the same can be done for the columns. In the end, we're left with a 3x3 sliding puzzle, which can be solved by a simple BFS. ## Checking possibility It is a well-known result that a sliding puzzle is solvable IFF the parity of the number of inversions is even. https://datawookie.dev/blog/2019/04/sliding-puzzle-solvable/ So we start by checking this. ## Row/column reduction Just play the game a couple of times to build some intuition https://icherya.github.io/Fifteen-Puzzle/. We can pretty easily move things into place as long as we don't move already fixed blocks. However, there is one very annoying case: ![image](https://hackmd.io/_uploads/rJDY4CdwJe.png) The way I solved it was simply to hardcode a solution once they were moved into place. It looked something like "DLUURDDLURDLUURDLURDLRDLU" (although I don't remember where they were supposed to be relative to each other to work). The way I implemented the problem was to create a primitive "move block x to position p". This was then implemented by creating a function that moves the empty block to a certain position in the fewest number of steps using a BFS, and repeatedly calling that to move our block to the correct spot. Implementing this bug-free is the hard part of the problem. ## BFS You can debug your implementation here https://po.kattis.com/problems/attaspelet. [Here](https://gist.github.com/Matistjati/0f6e83d2bdb2127791f86710e833a322) is my implementation. It's very long, as any solution to this problem is going to be. You can dm me about details if you're wondering about anything.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully