Submission #1000569
Source Code Expand
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public int mod = 1000000007; public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); TaskA.Event[] evs = new TaskA.Event[2 * n]; for (int i = 0; i < n; i++) { evs[i] = new TaskA.Event(in.nextInt(), +1); } for (int i = 0; i < n; i++) { evs[i + n] = new TaskA.Event(in.nextInt(), -1); } Arrays.sort(evs); int curcount = 0; long nways = 1; for (int i = 0; i < 2 * n; i++) { if (evs[i].b == +1) { if (curcount < 0) { nways = nways * (-curcount) % mod; } curcount++; } else { if (curcount > 0) { nways = nways * curcount % mod; } curcount--; } } out.println(nways); } static class Event implements Comparable<TaskA.Event> { public int a; public int b; public Event(int a, int b) { this.a = a; this.b = b; } public int compareTo(TaskA.Event other) { return a - other.a; } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | lewin |
Language | Java8 (OpenJDK 1.8.0) |
Score | 500 |
Code Size | 2978 Byte |
Status | AC |
Exec Time | 548 ms |
Memory | 31236 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 | 389 ms | 31236 KB |
001.txt | AC | 282 ms | 19084 KB |
002.txt | AC | 281 ms | 20724 KB |
003.txt | AC | 267 ms | 21916 KB |
004.txt | AC | 457 ms | 30852 KB |
005.txt | AC | 548 ms | 30740 KB |
006.txt | AC | 543 ms | 31064 KB |
007.txt | AC | 485 ms | 31140 KB |
008.txt | AC | 477 ms | 30988 KB |
009.txt | AC | 502 ms | 30584 KB |
010.txt | AC | 528 ms | 31160 KB |
011.txt | AC | 484 ms | 31108 KB |
example0.txt | AC | 99 ms | 8528 KB |
example1.txt | AC | 99 ms | 8404 KB |