CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Modern art
Sender:Farah
Submission time:2024-11-11 17:46:16 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#220.00 sdetails
#230.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#280.00 sdetails
#29ACCEPTED0.00 sdetails
#300.00 sdetails
#31ACCEPTED0.00 sdetails
#320.00 sdetails
#330.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#380.00 sdetails
#39ACCEPTED0.00 sdetails
#400.00 sdetails
#41ACCEPTED0.00 sdetails
#420.00 sdetails
#430.00 sdetails
#440.00 sdetails
#45ACCEPTED0.00 sdetails
#460.00 sdetails
#47ACCEPTED0.00 sdetails
#480.00 sdetails
#49ACCEPTED0.00 sdetails
#500.00 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, P;
    cin >> A >> P;
    
    if((4LL * A - P) < 0 || (4LL * A - P) % 2 != 0){
        cout << "IMPOSSIBLE";
        return 0;
    }
    
    int grid_size = 50;
    vector<vector<char>> grid(grid_size, vector<char>(grid_size, '0'));
    int cx = grid_size / 2;
    int cy = grid_size / 2;
    vector<pair<int, int>> dirs = { {-1,0}, {1,0}, {0,-1}, {0,1} };
    queue<pair<int, int>> q;
    q.push({cx, cy});
    grid[cx][cy] = '1';
    A--;
    ll current_P = 4;
    vector<pair<int, int>> black_pixels;
    black_pixels.emplace_back(cx, cy);
    
    while(A > 0 && !q.empty()){
        auto [x, y] = q.front(); q.pop();
        for(auto &[dx, dy] : dirs){
            int nx = x + dx;
            int ny = y + dy;
            if(nx < 0 || nx >= grid_size || ny < 0 || ny >= grid_size) continue;
            if(grid[nx][ny] == '0'){
                ll added_P = 4;
                for(auto &[ddx, ddy] : dirs){
                    int adj_x = nx + ddx;
                    int adj_y = ny + ddy;
                    if(adj_x < 0 || adj_x >= grid_size || adj_y < 0 || adj_y >= grid_size) continue;
                    if(grid[adj_x][adj_y] == '1') added_P -= 2;
                }
                if(current_P + added_P > P){
                    continue;
                }
                grid[nx][ny] = '1';
                current_P += added_P;
                A--;
                q.push({nx, ny});
                black_pixels.emplace_back(nx, ny);
                if(A == 0) break;
            }
        }
    }
    
    if(A != 0 || current_P != P){
        cout << "IMPOSSIBLE";
        return 0;
    }
    
    int min_x = grid_size, max_x = -1, min_y = grid_size, max_y = -1;
    for(auto &[x, y] : black_pixels){
        min_x = min(min_x, x);
        max_x = max(max_x, x);
        min_y = min(min_y, y);
        max_y = max(max_y, y);
    }
    
    min_x = max(min_x -1, 0);
    max_x = min(max_x +1, grid_size-1);
    min_y = max(min_y -1, 0);
    max_y = min(max_y +1, grid_size-1);
    
    vector<vector<char>> subgrid;
    for(int i = min_x; i <= max_x; ++i){
        vector<char> row;
        for(int j = min_y; j <= max_y; ++j){
            row.push_back(grid[i][j]);
        }
        subgrid.push_back(row);
    }
    
    int sub_rows = subgrid.size();
    int sub_cols = subgrid[0].size();
    for(int i = 0; i < sub_rows; ++i){
        subgrid[i][0] = '0';
        subgrid[i][sub_cols-1] = '0';
    }
    for(int j = 0; j < sub_cols; ++j){
        subgrid[0][j] = '0';
        subgrid[sub_rows-1][j] = '0';
    }
    
    ll final_P = 0;
    for(int i = 0; i < sub_rows; ++i){
        for(int j = 0; j < sub_cols; ++j){
            if(subgrid[i][j] == '1'){
                for(auto &[dx, dy] : dirs){
                    int ni = i + dx;
                    int nj = j + dy;
                    if(ni < 0 || ni >= sub_rows || nj < 0 || nj >= sub_cols || subgrid[ni][nj] == '0'){
                        final_P++;
                    }
                }
            }
        }
    }
    
    if(final_P != P){
        cout << "IMPOSSIBLE";
        return 0;
    }
    
    cout << "POSSIBLE\n";
    for(auto &row : subgrid){
        for(auto &c : row) cout << c;
        cout << '\n';
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
5 14

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 2

Verdict: ACCEPTED

input
6 14

correct output
POSSIBLE
000
010
010
010
...

user output
POSSIBLE
00000
00100
00100
01110
...

Test 3

Verdict: ACCEPTED

input
7 10

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 4

Verdict: ACCEPTED

input
5 5

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 5

Verdict: ACCEPTED

input
6 22

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Verdict: ACCEPTED

input
7 10

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 7

Verdict: ACCEPTED

input
5 20

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 8

Verdict: ACCEPTED

input
6 8

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 9

Verdict: ACCEPTED

input
7 4

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 10

Verdict: ACCEPTED

input
5 10

correct output
POSSIBLE
0000
0110
0110
0100
...

user output
POSSIBLE
0000
0110
0110
0010
...

Test 11

Verdict: ACCEPTED

input
10 25

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 12

Verdict:

input
10 22

correct output
POSSIBLE
000
010
010
010
...

user output
IMPOSSIBLE

Test 13

Verdict: ACCEPTED

input
10 14

correct output
POSSIBLE
0000
0110
0110
0110
...

user output
POSSIBLE
00000
00100
01110
01110
...

Test 14

Verdict: ACCEPTED

input
10 6

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 15

Verdict: ACCEPTED

input
10 37

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 16

Verdict: ACCEPTED

input
10 12

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 17

Verdict: ACCEPTED

input
10 39

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 18

Verdict: ACCEPTED

input
10 14

correct output
POSSIBLE
0000
0110
0110
0110
...

user output
POSSIBLE
00000
00100
01110
01110
...

Test 19

Verdict: ACCEPTED

input
10 4

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 20

Verdict: ACCEPTED

input
10 16

correct output
POSSIBLE
00000000
01111110
01111000
00000000

user output
POSSIBLE
00000
00100
01110
01110
...

Test 21

Verdict: ACCEPTED

input
100 239

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 22

Verdict:

input
100 202

correct output
POSSIBLE
000
010
010
010
...

user output
IMPOSSIBLE

Test 23

Verdict:

input
100 70

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 24

Verdict: ACCEPTED

input
100 32

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 25

Verdict: ACCEPTED

input
100 361

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 26

Verdict: ACCEPTED

input
100 48

correct output
POSSIBLE
00000000000000000000
01111111111111111110
01111111111111111110
01111111111111111110
...

user output
POSSIBLE
0000000000000
0000011100000
0000111110000
0001111111000
...

Test 27

Verdict: ACCEPTED

input
100 380

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 28

Verdict:

input
100 76

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 29

Verdict: ACCEPTED

input
100 8

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 30

Verdict:

input
100 98

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 31

Verdict: ACCEPTED

input
200 476

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 32

Verdict:

input
200 402

correct output
POSSIBLE
000
010
010
010
...

user output
IMPOSSIBLE

Test 33

Verdict:

input
200 120

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 34

Verdict: ACCEPTED

input
200 60

correct output
POSSIBLE
000000000000
011111111110
011111111110
011111111110
...

user output
POSSIBLE
00000000000000000
00001111111110000
00011111111111000
00111111111111100
...

Test 35

Verdict: ACCEPTED

input
200 721

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 36

Verdict: ACCEPTED

input
200 74

correct output
POSSIBLE
000000000000000000000000000000...

user output
POSSIBLE
00000000000000000000
00000000011100000000
00000000111110000000
00000001111111000000
...

Test 37

Verdict: ACCEPTED

input
200 759

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 38

Verdict:

input
200 134

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 39

Verdict: ACCEPTED

input
200 12

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 40

Verdict:

input
200 182

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 41

Verdict: ACCEPTED

input
1000 2373

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 42

Verdict:

input
1000 1998

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 43

Verdict:

input
1000 472

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 44

Verdict:

input
1000 286

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 45

Verdict: ACCEPTED

input
1000 3603

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 46

Verdict:

input
1000 228

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 47

Verdict: ACCEPTED

input
1000 3791

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 48

Verdict:

input
1000 552

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE

Test 49

Verdict: ACCEPTED

input
1000 48

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 50

Verdict:

input
1000 810

correct output
POSSIBLE
000000000000000000000000000000...

user output
IMPOSSIBLE