Submission #1000692


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[100001];
ll b[100001];
const int MOD = 1e9 + 7;
ll fact[100001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	fact[0]=1;
	for(int i = 1; i <= n; i++)
	{
		fact[i]=(fact[i-1]*i)%MOD;
	}
	ll sum = 0;
	for(int i =0;i<n;i++) 
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n;i++) 
	{
		cin>>b[i];
		sum-=b[i];
	}
	if(sum<0) swap(a,b);
	sort(a,a+n);
	sort(b,b+n);
	ll ans = 1;
	/*
	int ptr = 0;
	ll avi = 0;
	ll cnt = 0;
	for(int i = 0; i < n; i++)
	{
		while(ptr<n&&b[ptr]<a[i])
		{
			ptr++;
			avi++;
		}
		if(avi>0)
		{
			ans=(ans*fact[cnt])%MOD;
			avi-=cnt;
			cnt=0;
		}
		if(avi>0)
		{
			ans=(ans*avi)%MOD;
			avi--;
			cnt=0;
		}
		else
		{
			cnt++;
		}
	}
	ans=(ans*fact[cnt])%MOD;
	*/
	ll run = 1;
	for(int i = 1; i < n; i++)
	{
		if((a[i]>b[i])==(a[i-1]>b[i-1]))
		{
			run++;
		}
		else
		{
			ans=(ans*fact[run])%MOD;
			run = 1;
		}
	}
	ans=(ans*fact[run])%MOD;
	cout<<ans<<'\n';
}

Submission Info

Submission Time
Task A - 1D Matching
User zscoder
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1606 Byte
Status WA
Exec Time 40 ms
Memory 2560 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 3
WA × 11
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt WA 24 ms 1664 KB
001.txt WA 13 ms 2048 KB
002.txt WA 13 ms 1024 KB
003.txt WA 16 ms 2176 KB
004.txt WA 34 ms 2304 KB
005.txt WA 39 ms 2560 KB
006.txt WA 38 ms 2560 KB
007.txt WA 38 ms 2560 KB
008.txt WA 38 ms 2560 KB
009.txt WA 38 ms 2560 KB
010.txt AC 38 ms 2560 KB
011.txt WA 40 ms 2560 KB
example0.txt AC 5 ms 1792 KB
example1.txt AC 6 ms 1792 KB