CSES - COCI 2006/2007 #6 - Results
Submission details
Task:Kamen
Sender:untokarila
Submission time:2019-07-28 15:58:16 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#20.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.04 sdetails
#8ACCEPTED0.06 sdetails
#9ACCEPTED0.08 sdetails
#10ACCEPTED0.10 sdetails

Code

#include <iostream>
#define X first
#define Y second

using namespace std;

int r, c;
// board's dimensions

int u[31];
pair<int, int> p[31];
// u -> union find -ish structure
// p -> rock's position after physics simulation

char board[32][30002];
int track[32][30002] = {0};
// board : X = wall, . = empty space, O = rock
// track -> remembers rock's fall patterns

int id(int k){
    while(u[k]!=k) k = u[k];
    return k;
}

bool fall(int pos){
    int x = p[pos].X, y = p[pos].Y;
    if(board[x][y+1] == 'X') return 0;
    if(board[x][y+1] =='.'){p[pos].Y++; return 1;}
    if(board[x-1][y] =='.' && board[x-1][y+1] =='.'){
        p[pos].Y++; p[pos].X--;
        return 1;
    }
    if(board[x+1][y] =='.' && board[x+1][y+1] =='.'){
        p[pos].Y++; p[pos].X++;
        return 1;
    }
    return 0;
}
// physics simulation;

void drop(int pos){
    pos = id(pos);

    while(fall(pos)){
        int a = p[pos].X, b = p[pos].Y;
        if(!track[a][b]) track[a][b] = pos;
        else {
            u[pos] = track[a][b];
            pos = id(track[a][b]);
        }
    }

    int dx = p[pos].X, dy = p[pos].Y;
    board[dx][dy] = 'O';

    for(int i=-1; i<2; i++){
        int k = track[dx+i][dy-1];
        if(k && id(k)==pos && board[dx+i][dy-1] == '.'){
            p[k] = {dx+i, dy-1};
            u[k] = k;
        }
    }
}

int main(){

    cin >> r >> c;

    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            cin >> board[j][i];
        }
    }

    for(int i=1; i<=r; i++){ board[0][i] = 'X'; board[c+1][i] = 'X';}
    for(int i=0; i<c+2; i++){ board[i][r+1] = 'X'; board[i][0] = '.';}
    // draw edges

    for(int i=1; i<=c; i++){
            p[i] = {i, 0};
            u[i] = i;
            drop(i);
            p[i].Y++;
            board[p[i].X][p[i].Y] = '.';
    }
    // initialize union find

    int rocks;
    cin >> rocks;

    for(; rocks--;){
        int rock_pos;
        cin >> rock_pos;
        drop(rock_pos);
    }

    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            cout << board[j][i];
        } cout << '\n';
    }

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
5 5
.....
.....
..X..
.....
...

correct output
.....
.OO..
OOX..
OO...
OOOO.

user output
.....
.OO..
OOX..
OO...
OOOO.

Test 2

Verdict:

input
6 20
....................
..........X.X.......
X...XX.............X
...XX..........X....
...

correct output
....................
O...O.....X.X......O
X..OXX.........O...X
...XX..........X....
......OO.O....O...O.
...

user output
..........O.O.......
O...O..............O
X..OXX.........O...X
...XX..........X....
......
...
Truncated

Test 3

Verdict: ACCEPTED

input
10 10
..........
..........
.XX....X..
..........
...

correct output
..........
.OO....O..
.XX....X..
..........
.....O...O
...

user output
..........
.OO....O..
.XX....X..
..........
.....O...O
...
Truncated

Test 4

Verdict: ACCEPTED

input
15 15
...............
...............
...............
...............
...

correct output
...............
...............
...............
...............
......O........
...

user output
...............
...............
...............
...............
......O........
...
Truncated

Test 5

Verdict: ACCEPTED

input
30 7
.......
.......
......X
....X..
...

correct output
.......
.OOO..O
OOOOO.X
OOOOX..
OXXXX..
...

user output
.......
.OOO..O
OOOOO.X
OOOOX..
OXXXX..
...
Truncated

Test 6

Verdict: ACCEPTED

input
30 30
.................................

correct output
.................................

user output
..............................
...........O.........O........
...........X.........X.O...O

...
Truncated

Test 7

Verdict: ACCEPTED

input
30000 5
.....
.....
.....
.....
...

correct output
.....
.....
.....
.....
.O...
...

user output
.....
.....
.....
.....
.O...
...
Truncated

Test 8

Verdict: ACCEPTED

input
30000 13
.............
.............
...XX...XX...
.............
...

correct output
.............
...OO...OO...
...XX...XX...
O............
OO...OO...OO.
...

user output
.............
...OO...OO...
...XX...XX...
O............
OO...OO...OO.
...
Truncated

Test 9

Verdict: ACCEPTED

input
30000 21
.....................
.....................
.....................
.....................
...

correct output
.....................
.....................
.....................
.....................
.....................
...

user output
.....................
.....................
.....................
.....................
..
...
Truncated

Test 10

Verdict: ACCEPTED

input
30000 30
.................................

correct output
.................................

user output
..............................
..............................
............................

...
Truncated