Submission #3441402


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 f[] = new long[n+1];
        long d[] = new long[n*2];
        
        f[1]=1;
        for (int i = 2; i <= n; i++) {
        	f[i] = f[i-1] * i;
        	f[i] %= mod;
        }
        
        
        for (int i = 0; i < n; i++) {
        	d[i] = sc.nextLong()<<40;
        }
        for (int i = 0; i < n; i++) {
        	d[i+n] = sc.nextLong()<<40;
        	d[i+n] += 1;
        }
        sort(d);
        
        int pre=(int)(d[0]%2),mx=1,c=0,s=0;
        long ans=1;
        for (int i = 1; i < n*2; i++) {
        	if(d[i]%2==pre) {mx++;}
        	else {
        		c++; pre=(int)(d[i]%2);
        		if(c==2) {
        		  c=0;
        		  ans*=f[min(mx,s)]; ans%=mod; 
        		  if(mx>=s)mx=1+abs(mx-s);
        		  else {c=1;mx=1; s-=mx;}
        		  
        		}
        		else {s=mx;mx=1;}  
        	}
        }
    	ans*=f[mx];
    	ans%=mod;

        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 0
Code Size 2658 Byte
Status WA
Exec Time 296 ms
Memory 44896 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 2
WA × 12
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 230 ms 41716 KB
001.txt WA 178 ms 28420 KB
002.txt WA 190 ms 31912 KB
003.txt WA 193 ms 30304 KB
004.txt WA 259 ms 38112 KB
005.txt WA 276 ms 44896 KB
006.txt WA 271 ms 44616 KB
007.txt WA 292 ms 42416 KB
008.txt WA 276 ms 44296 KB
009.txt WA 296 ms 44816 KB
010.txt WA 276 ms 43760 KB
011.txt WA 273 ms 43048 KB
example0.txt AC 72 ms 18644 KB
example1.txt AC 70 ms 20308 KB