For the problem [problem:1827A], when in the question they mentioned that two reorderings are different, if the resultant array is different. When I check the submitted code with the below testcase, I got answer 4. But when I dry run for the testcase in the note, I found the resultant array are same. Hence the unique ways of reordering must be 2. Anyone plz explain and don't downvote for the question. Thanks in advance.↵
↵
↵
↵
↵
**CODE**↵
↵
~~~~~↵
int n;↵
cin >> n;↵
vector<int> a(n), b(n);↵
for(int i = 0; i < n; i++) cin >> a[i];↵
for(int i = 0; i < n; i++) cin >> b[i];↵
sort(a.begin(), a.end());↵
sort(b.begin(), b.end());↵
ll ans = 1ll;↵
bool flag = false;↵
if(a[n - 1] <= b[n - 1]) flag = true;↵
else {↵
int i = 0, j = 0, cnt = 0;↵
while(i < n) {↵
int val = a[i];↵
while(j < n && val > b[j]) {↵
j++;↵
}↵
ll res = (j - i);↵
ans *= (res % mod);↵
ans %= mod;↵
i++;↵
}↵
}↵
↵
if(flag) cout << 0 << endl;↵
else cout << ans << endl;↵
~~~~~↵
↵
↵
↵
↵
↵
**CODE**↵
↵
~~~~~↵
int n;↵
cin >> n;↵
vector<int> a(n), b(n);↵
for(int i = 0; i < n; i++) cin >> a[i];↵
for(int i = 0; i < n; i++) cin >> b[i];↵
sort(a.begin(), a.end());↵
sort(b.begin(), b.end());↵
ll ans = 1ll;↵
bool flag = false;↵
if(a[n - 1] <= b[n - 1]) flag = true;↵
else {↵
int i = 0, j = 0, cnt = 0;↵
while(i < n) {↵
int val = a[i];↵
while(j < n && val > b[j]) {↵
j++;↵
}↵
ll res = (j - i);↵
ans *= (res % mod);↵
ans %= mod;↵
i++;↵
}↵
}↵
↵
if(flag) cout << 0 << endl;↵
else cout << ans << endl;↵
~~~~~↵
↵