Submission #2825845
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 || (ai != N) && 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 | 2703 Byte |
Status | AC |
Exec Time | 276 ms |
Memory | 43812 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 | 266 ms | 36732 KB |
001.txt | AC | 163 ms | 28500 KB |
002.txt | AC | 163 ms | 30544 KB |
003.txt | AC | 210 ms | 30652 KB |
004.txt | AC | 244 ms | 39016 KB |
005.txt | AC | 267 ms | 43416 KB |
006.txt | AC | 261 ms | 40792 KB |
007.txt | AC | 268 ms | 40996 KB |
008.txt | AC | 265 ms | 40832 KB |
009.txt | AC | 269 ms | 40180 KB |
010.txt | AC | 276 ms | 43812 KB |
011.txt | AC | 248 ms | 41024 KB |
example0.txt | AC | 68 ms | 20436 KB |
example1.txt | AC | 69 ms | 23124 KB |