Submission #2825763
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) { int a = A[ai]; int b = B[bi]; if( a < b ) { ai++; if( ab < 0 ) { ans = ans * (ab*-1) % MOD; } ab++; } else { bi++; if( ab > 0 ) { ans = ans * ab % MOD; } ab--; } } ans = ans * Math.abs(ab) % MOD; 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 | 0 |
Code Size | 2778 Byte |
Status | WA |
Exec Time | 278 ms |
Memory | 45068 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 238 ms | 37072 KB |
001.txt | AC | 152 ms | 25940 KB |
002.txt | WA | 186 ms | 28284 KB |
003.txt | AC | 189 ms | 32516 KB |
004.txt | AC | 258 ms | 39020 KB |
005.txt | AC | 259 ms | 41624 KB |
006.txt | AC | 276 ms | 41456 KB |
007.txt | AC | 278 ms | 43068 KB |
008.txt | WA | 277 ms | 44416 KB |
009.txt | AC | 263 ms | 41260 KB |
010.txt | WA | 266 ms | 45068 KB |
011.txt | AC | 264 ms | 40896 KB |
example0.txt | AC | 73 ms | 18644 KB |
example1.txt | AC | 73 ms | 20436 KB |