Submission #4597041
Source Code Expand
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; public class Main { static final int C = 200_000; void submit() { int n = nextInt(); int[] a = new int[n]; int sz = 0; for (int i = 0; i < n; i++) { int x = nextInt() - 1; if (sz > 0 && x == a[sz - 1]) { continue; } a[sz++] = x; } n = sz; a = Arrays.copyOf(a, n); int[] aux = new int[C]; int prev = 1; for (int i = n - 1; i >= 0; i--) { int symb = a[i]; aux[symb] += prev; if (aux[symb] >= P) { aux[symb] -= P; } prev = aux[symb]; } out.println(prev); } static final int P = 1_000_000_007; void test() { } void stress() { for (int tst = 0;; tst++) { if (false) { throw new AssertionError(); } System.err.println(tst); } } Main() throws IOException { is = System.in; out = new PrintWriter(System.out); submit(); // stress(); // test(); out.close(); } static final Random rng = new Random(); static int rand(int l, int r) { return l + rng.nextInt(r - l + 1); } public static void main(String[] args) throws IOException { new Main(); } private InputStream is; PrintWriter out; private byte[] buf = new byte[1 << 14]; private int bufSz = 0, bufPtr = 0; private int readByte() { if (bufSz == -1) throw new RuntimeException("Reading past EOF"); if (bufPtr >= bufSz) { bufPtr = 0; try { bufSz = is.read(buf); } catch (IOException e) { throw new RuntimeException(e); } if (bufSz <= 0) return -1; } return buf[bufPtr++]; } private boolean isTrash(int c) { return c < 33 || c > 126; } private int skip() { int b; while ((b = readByte()) != -1 && isTrash(b)) ; return b; } String nextToken() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!isTrash(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } String nextString() { int b = readByte(); StringBuilder sb = new StringBuilder(); while (!isTrash(b) || b == ' ') { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } double nextDouble() { return Double.parseDouble(nextToken()); } char nextChar() { return (char) skip(); } int nextInt() { int ret = 0; int b = skip(); if (b != '-' && (b < '0' || b > '9')) { throw new InputMismatchException(); } boolean neg = false; if (b == '-') { neg = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { ret = ret * 10 + (b - '0'); } else { if (b != -1 && !isTrash(b)) { throw new InputMismatchException(); } return neg ? -ret : ret; } b = readByte(); } } long nextLong() { long ret = 0; int b = skip(); if (b != '-' && (b < '0' || b > '9')) { throw new InputMismatchException(); } boolean neg = false; if (b == '-') { neg = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { ret = ret * 10 + (b - '0'); } else { if (b != -1 && !isTrash(b)) { throw new InputMismatchException(); } return neg ? -ret : ret; } b = readByte(); } } }
Submission Info
Submission Time | |
---|---|
Task | B - Reversi |
User | mmaxio |
Language | Java8 (OpenJDK 1.8.0) |
Score | 700 |
Code Size | 3330 Byte |
Status | AC |
Exec Time | 106 ms |
Memory | 25556 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 95 ms | 24404 KiB |
02.txt | AC | 102 ms | 21716 KiB |
03.txt | AC | 93 ms | 22100 KiB |
04.txt | AC | 93 ms | 24916 KiB |
05.txt | AC | 90 ms | 23508 KiB |
06.txt | AC | 90 ms | 24148 KiB |
07.txt | AC | 90 ms | 23636 KiB |
08.txt | AC | 91 ms | 22356 KiB |
09.txt | AC | 104 ms | 24148 KiB |
10.txt | AC | 98 ms | 23124 KiB |
11.txt | AC | 103 ms | 22612 KiB |
12.txt | AC | 106 ms | 25556 KiB |
13.txt | AC | 93 ms | 22740 KiB |
14.txt | AC | 92 ms | 23380 KiB |
15.txt | AC | 91 ms | 24020 KiB |
16.txt | AC | 91 ms | 22612 KiB |
17.txt | AC | 91 ms | 23508 KiB |
18.txt | AC | 94 ms | 23636 KiB |
19.txt | AC | 91 ms | 25556 KiB |
20.txt | AC | 91 ms | 23508 KiB |
21.txt | AC | 91 ms | 24020 KiB |
22.txt | AC | 91 ms | 22484 KiB |
23.txt | AC | 100 ms | 24020 KiB |
24.txt | AC | 93 ms | 21844 KiB |
25.txt | AC | 69 ms | 20436 KiB |
26.txt | AC | 67 ms | 18132 KiB |
27.txt | AC | 68 ms | 18644 KiB |
28.txt | AC | 68 ms | 22228 KiB |
29.txt | AC | 69 ms | 20308 KiB |
30.txt | AC | 69 ms | 20820 KiB |
s1.txt | AC | 69 ms | 22612 KiB |
s2.txt | AC | 69 ms | 20948 KiB |
s3.txt | AC | 67 ms | 23124 KiB |