Submission #2825834
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class Main { static int N; static int[] A; static int[] B; static int MOD = 1_000_000_007; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); N = sc.nextInt(); A = sc.nextIntArray(N); B = sc.nextIntArray(N); System.out.println( solve() ); } static long solve() { Arrays.sort(A); Arrays.sort(B); long ans = 1; int ai = 0; int bi = 0; int ab = 0; while(ai < N || bi < N) { if( bi == N ) { ans = ans * -ab % MOD; ai++; ab++; } else if( ai == N ) { ans = ans * ab % MOD; bi++; ab--; } else if( A[ai] < B[bi] ) { if( ab < 0 ) { ans = ans * -ab % MOD; } ai++; ab++; } else { if( ab > 0 ) { ans = ans * ab % MOD; } bi++; ab--; } } return ans; } @SuppressWarnings("unused") static class FastScanner { private BufferedReader reader; private StringTokenizer tokenizer; FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } long nextLong() { return Long.parseLong(next()); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | kusomushi |
Language | Java8 (OpenJDK 1.8.0) |
Score | 500 |
Code Size | 2926 Byte |
Status | AC |
Exec Time | 310 ms |
Memory | 43548 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
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 | 259 ms | 36712 KB |
001.txt | AC | 166 ms | 27064 KB |
002.txt | AC | 183 ms | 28384 KB |
003.txt | AC | 194 ms | 30432 KB |
004.txt | AC | 240 ms | 39084 KB |
005.txt | AC | 264 ms | 39980 KB |
006.txt | AC | 310 ms | 40600 KB |
007.txt | AC | 301 ms | 40516 KB |
008.txt | AC | 264 ms | 43548 KB |
009.txt | AC | 272 ms | 41892 KB |
010.txt | AC | 264 ms | 42204 KB |
011.txt | AC | 255 ms | 40864 KB |
example0.txt | AC | 71 ms | 20820 KB |
example1.txt | AC | 70 ms | 21076 KB |