QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508243#5864. Square TilesSaulGoodman20 ✓4ms3620kbC++142.7kb2024-08-07 10:46:462024-08-07 10:46:50

Judging History

你现在查看的是最新测评结果

  • [2024-08-07 10:46:50]
  • 评测
  • 测评结果:20
  • 用时:4ms
  • 内存:3620kb
  • [2024-08-07 10:46:46]
  • 提交

answer

#include <iostream>
using namespace std;


int main() {
    // freopen("./input.txt", "r", stdin);
    // freopen("./output.txt", "w", stdout);

    const size_t MAX_ROWS = 100;

    auto print_tiles = [](char picture[100][100], int rows, int cols) {
        for(int j = 0; j < rows; j++) {
            for(int k = 0; k < cols; k++) {
                cout << picture[j][k];
            }
            cout << endl;
        }
    };

    //read input files and store in variables
    int num_pictures = 0;
    cin >> num_pictures;

    //loop through each picture and solve the problem
    for(int case_index = 1; case_index <= num_pictures; case_index++) {
        int rows, cols;
        cin >> rows >> cols;

        //store the picture in a 2D array & count number of blue tiles
        char picture[MAX_ROWS][MAX_ROWS];
        int blue_tiles = 0;
        for(int j = 0; j < rows; j++) {
            for(int k = 0; k < cols; k++) {
                cin >> picture[j][k];

                if(picture[j][k] == '#') {
                    blue_tiles++;
                }
            }
        }

        // Check if the number of blue tiles is divisible by 4 (since 4 blue tiles can be replaced by 1 red tile)
        if(blue_tiles % 4 != 0) {
            cout << "Case #" << case_index << ":" << endl;
            cout << "Impossible" << endl;
            continue;
        }

        // If there is no blue tile, then the picture is already solved
        if(blue_tiles == 0) {
            cout << "Case #" << case_index << ":" << endl;
            print_tiles(picture, rows, cols);
            continue;
        }

        //Go through each tile and try to fill red tile
        for(int r = 0; r < rows; r++) {
            for(int c = 0; c < cols; c++) {
                if(picture[r][c] == '#') {
                    //Check if the tile can be replaced by red tile
                    if(r + 1 < rows && c + 1 < cols && picture[r][c+1] == '#' && picture[r+1][c] == '#' && picture[r+1][c+1] == '#') {
                        picture[r][c] = '/';
                        picture[r][c+1] = '\\';
                        picture[r+1][c] = '\\';
                        picture[r+1][c+1] = '/';

                        blue_tiles -= 4;
                    }
                }
            }
        }

        //Find if there is any blue tile left
        if(blue_tiles != 0) {
            cout << "Case #" << case_index << ":" << endl;
            cout << "Impossible" << endl;
            continue;
        }
        else { //Output the result
            cout << "Case #" << case_index << ":" << endl;
            print_tiles(picture, rows, cols);
        }
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3620kb

input:

20
2 3
###
###
1 1
.
4 5
.##..
.####
.####
.##..
5 5
####.
####.
..##.
####.
##...
3 3
...
.##
.##
6 6
######
######
######
######
....##
..####
6 3
##.
##.
###
###
.##
.##
6 6
.####.
##..##
#.....
#..###
##...#
.####.
3 3
##.
##.
##.
1 1
#
6 3
##.
###
..#
.##
.##
...
5 5
####.
####.
####.
####.
##....

output:

Case #1:
Impossible
Case #2:
.
Case #3:
./\..
.\//\
./\\/
.\/..
Case #4:
/\/\.
\/\/.
../\.
/\\/.
\/...
Case #5:
...
./\
.\/
Case #6:
Impossible
Case #7:
Impossible
Case #8:
Impossible
Case #9:
Impossible
Case #10:
Impossible
Case #11:
Impossible
Case #12:
Impossible
Case #13:
/\/\/\
\/\/\/
../\..
/\...

result:

ok 81 lines

Subtask #2:

score: 10
Accepted

Test #2:

score: 10
Accepted
time: 4ms
memory: 3620kb

input:

50
2 3
###
###
1 1
.
4 5
.##..
.####
.####
.##..
42 30
######.####.##..##...##...####
######.####.########.##.######
######.##.....##..##....######
######.######.##.##..####.####
.##.##...####.##.########..##.
.##.##.##...##...######.##.##.
####...####.##.####..##.######
####.##..##....##.######..##...

output:

Case #1:
Impossible
Case #2:
.
Case #3:
./\..
.\//\
./\\/
.\/..
Case #4:
/\/\/\./\/\./\../\.../\.../\/\
\/\/\/.\/\/.\//\\//\.\/./\\/\/
/\/\/\./\.....\/..\/....\//\/\
\/\/\/.\//\/\./\./\../\/\.\/\/
./\./\...\/\/.\/.\//\\/\/../\.
.\/.\/./\.../\.../\\//\./\.\/.
/\/\...\//\.\/./\\/..\/.\//\/\
\/\/./\..\...

result:

ok 1297 lines

Extra Test:

score: 0
Extra Test Passed