Solution
Solution
#include<bits/stdc++.h>
using namespace std;
#define long long int
void rotate90(vector<vector<int>>&mat)
{
int n=mat.size();
for(int i=0;i<n/2;I++) // we will considerall cycle one by one
{
for(int j=i;j<n-i-1;j++) // we consider element in group of 4 like g1,g2,g3,g4
{
// swaping will be done in colckwise manner
int val=mat[i][j];
mat[i][j]=mat[n-1-j][i]; // move g4 to g1
mat[n-1-j][i]=mat[n-1-i][n-1-j]; // g3 to g4
mat[n-1-i][n-1-j]=mat[j][n-1-i]; // g2 to g3
mat[j][n-1-i]=val; // g1 to g2
}
}
}
int main()
{
vector<vector<int>>mat={{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
rotate90(mat);
int n=mat.size();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<mat[i][j]<<" "; // printing matrix after rotating 90 degree coclwise.
}
cout<<"\n";
}
}
Problem-16 sol)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll M = 998244353;
const ll N = 5010;
ll fact[N];
ll fact_inverse[N];