Task: | Modern art |
Sender: | Farah |
Submission time: | 2024-11-11 17:49:57 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | WRONG ANSWER | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | WRONG ANSWER | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | WRONG ANSWER | 0.00 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | WRONG ANSWER | 0.00 s | details |
#23 | WRONG ANSWER | 0.00 s | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.00 s | details |
#26 | WRONG ANSWER | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | WRONG ANSWER | 0.00 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | WRONG ANSWER | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | WRONG ANSWER | 0.00 s | details |
#33 | WRONG ANSWER | 0.00 s | details |
#34 | WRONG ANSWER | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | WRONG ANSWER | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | WRONG ANSWER | 0.00 s | details |
#39 | ACCEPTED | 0.00 s | details |
#40 | WRONG ANSWER | 0.00 s | details |
#41 | ACCEPTED | 0.00 s | details |
#42 | WRONG ANSWER | 0.00 s | details |
#43 | WRONG ANSWER | 0.00 s | details |
#44 | WRONG ANSWER | 0.00 s | details |
#45 | ACCEPTED | 0.00 s | details |
#46 | WRONG ANSWER | 0.00 s | details |
#47 | ACCEPTED | 0.00 s | details |
#48 | WRONG ANSWER | 0.00 s | details |
#49 | ACCEPTED | 0.00 s | details |
#50 | WRONG ANSWER | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:20:40: warning: variable 'min_P_final' set but not used [-Wunused-but-set-variable] 20 | int final_w, final_h, protrusions, min_P_final; | ^~~~~~~~~~~
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; // Check if P is within the valid range and (4*A - P) is even if(P < 2*A + 2 || (4LL * A - P) < 0 || (4LL * A - P) % 2 != 0){ cout << "IMPOSSIBLE"; return 0; } bool possible = false; int final_w, final_h, protrusions, min_P_final; // Iterate over possible rectangle dimensions for(int w=1; w<=A && !possible; w++){ for(int h=1; h<=A/w && !possible; h++){ if(w*h > A) continue; int min_P = 2*(w + h); int needed_protrusions = A - w*h; // Each protrusion increases perimeter by 2 int max_P = min_P + 2*needed_protrusions; if(P == max_P){ final_w = w; final_h = h; protrusions = needed_protrusions; min_P_final = min_P; possible = true; } } } if(!possible){ cout << "IMPOSSIBLE"; return 0; } int grid_rows = final_h + 2; int grid_cols = final_w + 2; vector<vector<char>> grid(grid_rows, vector<char>(grid_cols, '0')); // Fill the initial rectangle for(int i=1; i<=final_h; i++) { for(int j=1; j<=final_w; j++) { grid[i][j] = '1'; } } ll current_P = 2*(final_w + final_h); // Initialize perimeter correctly int added = 0; // Directions: Up, Down, Left, Right vector<pair<int, int>> dirs = { {-1,0}, {1,0}, {0,-1}, {0,1} }; // Attempt to add protrusions to reach the desired perimeter for(int i=1; i<=final_h && added < protrusions; i++){ for(int j=1; j<=final_w && added < protrusions; j++){ if(added >= protrusions) break; // Try to add protrusions to the top if(i >1 && grid[i-1][j] == '0'){ grid[i-1][j] = '1'; current_P += 2; added++; continue; } // Try to add protrusions to the bottom if(i < final_h && grid[i+1][j] == '0'){ grid[i+1][j] = '1'; current_P += 2; added++; continue; } // Try to add protrusions to the left if(j >1 && grid[i][j-1] == '0'){ grid[i][j-1] = '1'; current_P += 2; added++; continue; } // Try to add protrusions to the right if(j < final_w && grid[i][j+1] == '0'){ grid[i][j+1] = '1'; current_P += 2; added++; continue; } } } // After adding protrusions, ensure we have added the required number if(added != protrusions){ cout << "IMPOSSIBLE"; return 0; } // Determine the bounding box of the figure int min_x = grid_rows, max_x = -1, min_y = grid_cols, max_y = -1; for(int i=1; i<=final_h; i++) { for(int j=1; j<=final_w; j++) { if(grid[i][j] == '1'){ min_x = min(min_x, i); max_x = max(max_x, i); min_y = min(min_y, j); max_y = max(max_y, j); } } } // Include protrusions in the bounding box min_x = max(min_x -1, 0); max_x = min(max_x +1, grid_rows-1); min_y = max(min_y -1, 0); max_y = min(max_y +1, grid_cols-1); // Extract the subgrid containing the figure 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(); // Ensure the boundary of the subgrid is white 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'; } // Recalculate the perimeter to verify correctness ll final_P = 0; for(int i=1; i<sub_rows-1; i++){ for(int j=1; j<sub_cols-1; j++){ if(subgrid[i][j] == '1'){ for(auto &[dx, dy] : dirs){ int ni = i + dx; int nj = j + dy; if(subgrid[ni][nj] == '0') final_P++; } } } } // Verify if the calculated perimeter matches the desired perimeter if(final_P != P){ cout << "IMPOSSIBLE"; return 0; } // Output the final grid 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: WRONG ANSWER
input |
---|
6 14 |
correct output |
---|
POSSIBLE 000 010 010 010 ... |
user output |
---|
IMPOSSIBLE |
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: WRONG ANSWER
input |
---|
5 10 |
correct output |
---|
POSSIBLE 0000 0110 0110 0100 ... |
user output |
---|
IMPOSSIBLE |
Test 11
Verdict: ACCEPTED
input |
---|
10 25 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 12
Verdict: WRONG ANSWER
input |
---|
10 22 |
correct output |
---|
POSSIBLE 000 010 010 010 ... |
user output |
---|
IMPOSSIBLE |
Test 13
Verdict: WRONG ANSWER
input |
---|
10 14 |
correct output |
---|
POSSIBLE 0000 0110 0110 0110 ... |
user output |
---|
IMPOSSIBLE |
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: WRONG ANSWER
input |
---|
10 14 |
correct output |
---|
POSSIBLE 0000 0110 0110 0110 ... |
user output |
---|
IMPOSSIBLE |
Test 19
Verdict: ACCEPTED
input |
---|
10 4 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 20
Verdict: WRONG ANSWER
input |
---|
10 16 |
correct output |
---|
POSSIBLE 00000000 01111110 01111000 00000000 |
user output |
---|
IMPOSSIBLE |
Test 21
Verdict: ACCEPTED
input |
---|
100 239 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 22
Verdict: WRONG ANSWER
input |
---|
100 202 |
correct output |
---|
POSSIBLE 000 010 010 010 ... |
user output |
---|
IMPOSSIBLE |
Test 23
Verdict: WRONG ANSWER
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: WRONG ANSWER
input |
---|
100 48 |
correct output |
---|
POSSIBLE 00000000000000000000 01111111111111111110 01111111111111111110 01111111111111111110 ... |
user output |
---|
IMPOSSIBLE |
Test 27
Verdict: ACCEPTED
input |
---|
100 380 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 28
Verdict: WRONG ANSWER
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: WRONG ANSWER
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: WRONG ANSWER
input |
---|
200 402 |
correct output |
---|
POSSIBLE 000 010 010 010 ... |
user output |
---|
IMPOSSIBLE |
Test 33
Verdict: WRONG ANSWER
input |
---|
200 120 |
correct output |
---|
POSSIBLE 000000000000000000000000000000... |
user output |
---|
IMPOSSIBLE |
Test 34
Verdict: WRONG ANSWER
input |
---|
200 60 |
correct output |
---|
POSSIBLE 000000000000 011111111110 011111111110 011111111110 ... |
user output |
---|
IMPOSSIBLE |
Test 35
Verdict: ACCEPTED
input |
---|
200 721 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 36
Verdict: WRONG ANSWER
input |
---|
200 74 |
correct output |
---|
POSSIBLE 000000000000000000000000000000... |
user output |
---|
IMPOSSIBLE |
Test 37
Verdict: ACCEPTED
input |
---|
200 759 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 38
Verdict: WRONG ANSWER
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: WRONG ANSWER
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: WRONG ANSWER
input |
---|
1000 1998 |
correct output |
---|
POSSIBLE 000000000000000000000000000000... |
user output |
---|
IMPOSSIBLE |
Test 43
Verdict: WRONG ANSWER
input |
---|
1000 472 |
correct output |
---|
POSSIBLE 000000000000000000000000000000... |
user output |
---|
IMPOSSIBLE |
Test 44
Verdict: WRONG ANSWER
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: WRONG ANSWER
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: WRONG ANSWER
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: WRONG ANSWER
input |
---|
1000 810 |
correct output |
---|
POSSIBLE 000000000000000000000000000000... |
user output |
---|
IMPOSSIBLE |