Submission #4066542


Source Code Expand

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vi pc(n);
  vi cable(n);
  for(int i=0;i<n;i++)cin>>pc[i];
  for(int j=0;j<n;j++)cin>>cable[j];
  ll ans=1;
  sort(ALL(pc));
  sort(ALL(cable));
  int pccnt=0;
  int cacnt=0;
  vi p;vi c;
  while(pccnt!=n||cacnt!=n){
    if(pccnt==n){
      if(p.size()>0){
	ans*=p.size();
	p.pop_back();
	cacnt++;
      }
    }else if(cacnt==n){
      if(c.size()>0){
	ans*=c.size();
	c.pop_back();
	pccnt++;
      }
    }else{
      if(pc[pccnt]>cable[cacnt]){
	if(p.size()>0){
	  ans*=p.size();
	  p.pop_back();
	}else{
	  c.pb(1);
	}
	cacnt++;
      }else{
	if(c.size()>0){
	  ans*=c.size();
	  c.pop_back();
	}else{
	  p.pb(1);
	}
	pccnt++;
      }
    }
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User shi
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1599 Byte
Status AC
Exec Time 36 ms
Memory 2936 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 14
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 AC 22 ms 1280 KB
001.txt AC 9 ms 640 KB
002.txt AC 12 ms 768 KB
003.txt AC 13 ms 768 KB
004.txt AC 32 ms 1664 KB
005.txt AC 36 ms 1792 KB
006.txt AC 36 ms 1792 KB
007.txt AC 36 ms 1792 KB
008.txt AC 36 ms 1792 KB
009.txt AC 36 ms 1792 KB
010.txt AC 36 ms 2936 KB
011.txt AC 35 ms 1792 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB