Submission #2823837
Source Code Expand
import java.io.*; 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() { long[] F = new long[N+1]; long curr = 1; F[1] = 1; for (int i = 2; i <= N; i++) { curr = curr * i % MOD; F[i] = curr; } List<Integer> P = new ArrayList<>(); Arrays.sort(A); Arrays.sort(B); int ai = 0; int bi = 0; int ab = 0; int prev = 0; while(ai != N && bi != N) { int a = A[ai]; int b = B[bi]; if( a < b ) { ab++; ai++; } else { ab--; bi++; } if( ab == 0 ) { P.add(ai - prev); prev = ai; } } P.add(N - prev); long ans = F[P.get(0)]; for (int i = 1; i < P.size(); i++) { ans = ans * F[P.get(i)] % 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()); } double nextDouble() { return Double.parseDouble(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 | 3058 Byte |
Status | WA |
Exec Time | 315 ms |
Memory | 44748 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 | WA | 221 ms | 35968 KB |
001.txt | WA | 177 ms | 28660 KB |
002.txt | WA | 184 ms | 27620 KB |
003.txt | WA | 211 ms | 32188 KB |
004.txt | WA | 315 ms | 40516 KB |
005.txt | WA | 278 ms | 41048 KB |
006.txt | WA | 263 ms | 40364 KB |
007.txt | WA | 278 ms | 43376 KB |
008.txt | WA | 268 ms | 41116 KB |
009.txt | WA | 265 ms | 44748 KB |
010.txt | AC | 258 ms | 43100 KB |
011.txt | AC | 280 ms | 40028 KB |
example0.txt | AC | 69 ms | 20948 KB |
example1.txt | AC | 70 ms | 16852 KB |