From afeedd42d75eeb4be1d82e4b667976f163cd66ed Mon Sep 17 00:00:00 2001 From: Jagpreet Singh Khurana <119691733+Jagpreet153@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:36:33 +0530 Subject: [PATCH] feat: solved day 20 hard --- hard/day_20/solution.cpp | 106 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/hard/day_20/solution.cpp b/hard/day_20/solution.cpp index 8d3ad8d..0cef365 100644 --- a/hard/day_20/solution.cpp +++ b/hard/day_20/solution.cpp @@ -1 +1,105 @@ -//write your code here \ No newline at end of file +//write your code here +//Code by Jagpreet153 +#include +using namespace std; +void imp() { + cout << "IMPOSSIBLE" << endl; + exit(0); +} +int main () { + int n,m,a,b,c; + cin >> n >> m >> a >> b >> c; + if (n%2==1 && m%2==1) imp(); + if (a*2+b*2+c*4 res(n,string(m,0)); + for (int i=0;i used(20,0); + if (i>0) + used[res[i*2-1][j*2]]=1; + if (i>0) + used[res[i*2-1][j*2+1]]=1; + if (j>0) + used[res[i*2][j*2-1]]=1; + if (j>0) + used[res[i*2+1][j*2-1]]=1; + int fu=0; + while (used[fu]) + fu++; + used[fu]=1; + int su=0; + while (used[su]) + su++; + if (c>0) + { + res[i*2][j*2]=fu; + res[i*2][j*2+1]=fu; + res[i*2+1][j*2]=fu; + res[i*2+1][j*2+1]=fu; + c--; + } + else if (b>1) + { + res[i*2][j*2]=fu; + res[i*2][j*2+1]=su; + res[i*2+1][j*2]=fu; + res[i*2+1][j*2+1]=su; + b-=2; + } + else if (a>1) + { + res[i*2][j*2]=fu; + res[i*2][j*2+1]=fu; + res[i*2+1][j*2]=su; + res[i*2+1][j*2+1]=su; + a-=2; + } + else imp(); + } + if (n%2==1) + { + for (int i=0;i used(20,0); + if (i>0) + used[res[n-1][i*2-1]]=1; + if (n>1) + used[res[n-2][i*2]]=1; + if (n>1) + used[res[n-2][i*2+1]]=1; + int fu=0; + while (used[fu]) + fu++; + if (a>0) + { + res[n-1][i*2]=fu; + res[n-1][i*2+1]=fu; + a-=1; + } + else imp(); + } + } + if (swp) + swap(n,m); + for (int i=0;i