Submission #3441633


Source Code Expand

import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        long d[] = new long[n*2];
   
        
        
        for (int i = 0; i < n; i++) {
        	d[i] = sc.nextLong()*2;
        }
        for (int i = 0; i < n; i++) {
        	d[i+n] = sc.nextLong()*2;
        	d[i+n] += 1;
        }
        sort(d);
        
        int p=0,q=0;
        long ans=1;
        for (int i = 0; i < n*2; i++) {
        	if(d[i]%2==1) {if(q>0) {ans*=q;ans%=mod;q--;} else p++; }
        	else {
        		if(p>0) {ans*=p; ans%=mod; p--;} else q++;
        	}
        }

        out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Submission Info

Submission Time
Task A - 1D Matching
User mukku
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 2274 Byte
Status AC
Exec Time 313 ms
Memory 44936 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 223 ms 35936 KB
001.txt AC 155 ms 25276 KB
002.txt AC 184 ms 32892 KB
003.txt AC 177 ms 32164 KB
004.txt AC 261 ms 41192 KB
005.txt AC 265 ms 37952 KB
006.txt AC 274 ms 39524 KB
007.txt AC 313 ms 44936 KB
008.txt AC 265 ms 41772 KB
009.txt AC 279 ms 41712 KB
010.txt AC 267 ms 38812 KB
011.txt AC 267 ms 43632 KB
example0.txt AC 71 ms 21076 KB
example1.txt AC 70 ms 21204 KB