Submission #1102233
Source Code Expand
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out); new Main(new FastScanner(System.in), out); out.close(); } public Main(FastScanner in, PrintWriter out) { int N = in.nextInt(); int[] size = new int[2]; Point[] vs = new Point[2*N]; for (int x=0; x<2; x++) for (int i=0; i<N; i++) vs[i+x*N] = new Point(x, in.nextInt()); Arrays.sort(vs); long MODO = 1_000_000_007; long res = 1L; for (Point p : vs) { if (size[1-p.t] > 0) { res *= size[1-p.t]; res %= MODO; size[1-p.t]--; } else { size[p.t]++; } } out.println(res); } } class Point implements Comparable<Point> { int t, i; Point(int tt, int ii) { t=tt; i=ii; } public int compareTo(Point rhs) { return Integer.compare(i, rhs.i); } } class FastScanner{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars){ curChar = 0; try{ numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c) { return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } boolean isEndline(int c) { return c=='\n'||c=='\r'||c==-1; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String next(){ int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c)); return res.toString(); } String nextLine(){ int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isEndline(c)); return res.toString(); } }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | tehqin |
Language | Java8 (OpenJDK 1.8.0) |
Score | 500 |
Code Size | 2737 Byte |
Status | AC |
Exec Time | 498 ms |
Memory | 34708 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 | 323 ms | 28884 KB |
001.txt | AC | 214 ms | 18720 KB |
002.txt | AC | 231 ms | 20848 KB |
003.txt | AC | 236 ms | 22068 KB |
004.txt | AC | 457 ms | 29440 KB |
005.txt | AC | 463 ms | 34384 KB |
006.txt | AC | 439 ms | 34124 KB |
007.txt | AC | 480 ms | 34708 KB |
008.txt | AC | 447 ms | 34240 KB |
009.txt | AC | 498 ms | 34184 KB |
010.txt | AC | 488 ms | 34040 KB |
011.txt | AC | 464 ms | 34264 KB |
example0.txt | AC | 99 ms | 8400 KB |
example1.txt | AC | 98 ms | 8276 KB |