Submission #19564740
Source Code Expand
Copy
import java.math.BigInteger; public class Main { static int MOD = 998244353; public static void main(String[] args) throws Exception { var sc = new FastScanner(); var pw = new FastPrintStream(); solve(sc, pw); sc.close(); pw.flush(); pw.close(); } public static void solve(FastScanner sc, FastPrintStream pw) { int N = sc.nextInt(); int T = sc.nextInt(); int sum =0; int A[] = new int[N]; for (int i=0;i<N;i++) { A[i] = sc.nextInt(); } for (int i=1;i<N;i++) { sum +=Math.min(A[i]-A[i-1], T); } sum +=T; pw.println(sum); } static long modpow(int N, int K) { return BigInteger.valueOf(N).modPow(BigInteger.valueOf(K), BigInteger.valueOf(MOD)).longValue(); } public static int gcd(int a,int b) { if (b==0) { return a; } if (a<b) { return gcd(b,a); } return gcd(b,a%b); } } class Point implements Comparable { long a; long b; public int compareTo(Object o) { Point p = (Point) o; if (this.a > p.a) { return 1; } if (this.a < p.a) { return -1; } return 0; } } class FastPrintStream implements AutoCloseable { private static final int BUF_SIZE = 1 << 15; private final byte[] buf = new byte[BUF_SIZE]; private int ptr = 0; private final java.lang.reflect.Field strField; private final java.nio.charset.CharsetEncoder encoder; private java.io.OutputStream out; public FastPrintStream(java.io.OutputStream out) { this.out = out; java.lang.reflect.Field f; try { f = java.lang.String.class.getDeclaredField("value"); f.setAccessible(true); } catch (NoSuchFieldException | SecurityException e) { f = null; } this.strField = f; this.encoder = java.nio.charset.StandardCharsets.US_ASCII.newEncoder(); } public FastPrintStream(java.io.File file) throws java.io.IOException { this(new java.io.FileOutputStream(file)); } public FastPrintStream(java.lang.String filename) throws java.io.IOException { this(new java.io.File(filename)); } public FastPrintStream() { this(System.out); try { java.lang.reflect.Field f = java.io.PrintStream.class.getDeclaredField("autoFlush"); f.setAccessible(true); f.set(System.out, false); } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException e) { // ignore } } public FastPrintStream println() { if (ptr == BUF_SIZE) internalFlush(); buf[ptr++] = (byte) '\n'; return this; } public FastPrintStream println(java.lang.Object o) { return print(o).println(); } public FastPrintStream println(java.lang.String s) { return print(s).println(); } public FastPrintStream println(char[] s) { return print(s).println(); } public FastPrintStream println(char c) { return print(c).println(); } public FastPrintStream println(int x) { return print(x).println(); } public FastPrintStream println(long x) { return print(x).println(); } public FastPrintStream println(double d, int precision) { return print(d, precision).println(); } private FastPrintStream print(byte[] bytes) { int n = bytes.length; if (ptr + n > BUF_SIZE) { internalFlush(); try { out.write(bytes); } catch (java.io.IOException e) { throw new RuntimeException(); } } else { System.arraycopy(bytes, 0, buf, ptr, n); ptr += n; } return this; } public FastPrintStream print(java.lang.Object o) { return print(o.toString()); } public FastPrintStream print(java.lang.String s) { if (strField == null) { return print(s.getBytes()); } else { try { return print((byte[]) strField.get(s)); } catch (IllegalAccessException e) { return print(s.getBytes()); } } } public FastPrintStream print(char[] s) { try { return print(encoder.encode(java.nio.CharBuffer.wrap(s)).array()); } catch (java.nio.charset.CharacterCodingException e) { byte[] bytes = new byte[s.length]; for (int i = 0; i < s.length; i++) { bytes[i] = (byte) s[i]; } return print(bytes); } } public FastPrintStream print(char c) { if (ptr == BUF_SIZE) internalFlush(); buf[ptr++] = (byte) c; return this; } public FastPrintStream print(int x) { if (x == 0) { if (ptr == BUF_SIZE) internalFlush(); buf[ptr++] = '0'; return this; } int d = len(x); if (ptr + d > BUF_SIZE) internalFlush(); if (x < 0) { buf[ptr++] = '-'; x = -x; d--; } int j = ptr += d; while (x > 0) { buf[--j] = (byte) ('0' + (x % 10)); x /= 10; } return this; } public FastPrintStream print(long x) { if (x == 0) { if (ptr == BUF_SIZE) internalFlush(); buf[ptr++] = '0'; return this; } int d = len(x); if (ptr + d > BUF_SIZE) internalFlush(); if (x < 0) { buf[ptr++] = '-'; x = -x; d--; } int j = ptr += d; while (x > 0) { buf[--j] = (byte) ('0' + (x % 10)); x /= 10; } return this; } public FastPrintStream print(double d, int precision) { if (d < 0) { print('-'); d = -d; } d += Math.pow(10, -d) / 2; print((long) d).print('.'); d -= (long) d; for (int i = 0; i < precision; i++) { d *= 10; print((int) d); d -= (int) d; } return this; } private void internalFlush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (java.io.IOException e) { throw new RuntimeException(e); } } public void flush() { try { out.write(buf, 0, ptr); out.flush(); ptr = 0; } catch (java.io.IOException e) { throw new RuntimeException(e); } } public void close() { try { out.close(); } catch (java.io.IOException e) { throw new RuntimeException(e); } } private static int len(int x) { int d = 1; if (x >= 0) { d = 0; x = -x; } int p = -10; for (int i = 1; i < 10; i++, p *= 10) if (x > p) return i + d; return 10 + d; } private static int len(long x) { int d = 1; if (x >= 0) { d = 0; x = -x; } long p = -10; for (int i = 1; i < 19; i++, p *= 10) if (x > p) return i + d; return 19 + d; } } class FastScanner implements AutoCloseable { private final java.io.InputStream in; private final byte[] buf = new byte[2048]; private int ptr = 0; private int buflen = 0; public FastScanner(java.io.InputStream in) { this.in = in; } public FastScanner() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) return true; ptr = 0; try { buflen = in.read(buf); } catch (java.io.IOException e) { throw new RuntimeException(e); } return buflen > 0; } private int readByte() { return hasNextByte() ? buf[ptr++] : -1; } public boolean hasNext() { while (hasNextByte() && !(32 < buf[ptr] && buf[ptr] < 127)) ptr++; return hasNextByte(); } private StringBuilder nextSequence() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); for (int b = readByte(); 32 < b && b < 127; b = readByte()) { sb.appendCodePoint(b); } return sb; } public String next() { return nextSequence().toString(); } public String next(int len) { return new String(nextChars(len)); } public char nextChar() { if (!hasNextByte()) throw new java.util.NoSuchElementException(); return (char) readByte(); } public char[] nextChars() { StringBuilder sb = nextSequence(); int l = sb.length(); char[] dst = new char[l]; sb.getChars(0, l, dst, 0); return dst; } public char[] nextChars(int len) { if (!hasNext()) throw new java.util.NoSuchElementException(); char[] s = new char[len]; int i = 0; int b = readByte(); while (32 < b && b < 127 && i < len) { s[i++] = (char) b; b = readByte(); } if (i != len) { throw new java.util.NoSuchElementException( String.format("Next token has smaller length than expected.", len)); } return s; } public long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) throw new NumberFormatException(); while (true) { if ('0' <= b && b <= '9') { n = n * 10 + b - '0'; } else if (b == -1 || !(32 < b && b < 127)) { return minus ? -n : n; } else throw new NumberFormatException(); b = readByte(); } } public int nextInt() { return Math.toIntExact(nextLong()); } public double nextDouble() { return Double.parseDouble(next()); } public void close() { try { in.close(); } catch (java.io.IOException e) { throw new RuntimeException(e); } } }
Submission Info
Submission Time | |
---|---|
Task | B - 自動ドア |
User | goudezhao |
Language | Java (OpenJDK 11.0.6) |
Score | 100 |
Code Size | 11200 Byte |
Status | AC |
Exec Time | 122 ms |
Memory | 35788 KB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 50 / 50 | 50 / 50 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
Subtask1 | subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt, subtask1_28.txt, subtask1_29.txt, sample_01.txt, sample_02.txt |
Subtask2 | sample_01.txt, sample_02.txt, sample_23.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt, subtask1_28.txt, subtask1_29.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt, subtask2_26.txt, subtask2_27.txt, subtask2_28.txt, subtask2_29.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 86 ms | 33724 KB |
sample_02.txt | AC | 82 ms | 33764 KB |
sample_23.txt | AC | 92 ms | 33880 KB |
subtask1_01.txt | AC | 107 ms | 35532 KB |
subtask1_02.txt | AC | 102 ms | 35092 KB |
subtask1_03.txt | AC | 113 ms | 35212 KB |
subtask1_04.txt | AC | 108 ms | 35484 KB |
subtask1_05.txt | AC | 98 ms | 34732 KB |
subtask1_06.txt | AC | 98 ms | 34984 KB |
subtask1_07.txt | AC | 103 ms | 35204 KB |
subtask1_08.txt | AC | 112 ms | 35252 KB |
subtask1_09.txt | AC | 109 ms | 35304 KB |
subtask1_10.txt | AC | 101 ms | 34724 KB |
subtask1_11.txt | AC | 105 ms | 35152 KB |
subtask1_12.txt | AC | 104 ms | 35500 KB |
subtask1_13.txt | AC | 108 ms | 35456 KB |
subtask1_14.txt | AC | 103 ms | 35304 KB |
subtask1_15.txt | AC | 115 ms | 35656 KB |
subtask1_16.txt | AC | 101 ms | 35636 KB |
subtask1_17.txt | AC | 121 ms | 35364 KB |
subtask1_18.txt | AC | 117 ms | 35476 KB |
subtask1_19.txt | AC | 107 ms | 35700 KB |
subtask1_20.txt | AC | 111 ms | 35480 KB |
subtask1_21.txt | AC | 102 ms | 35524 KB |
subtask1_22.txt | AC | 116 ms | 35220 KB |
subtask1_23.txt | AC | 113 ms | 35652 KB |
subtask1_24.txt | AC | 115 ms | 35576 KB |
subtask1_25.txt | AC | 110 ms | 35400 KB |
subtask1_26.txt | AC | 122 ms | 35788 KB |
subtask1_27.txt | AC | 111 ms | 35404 KB |
subtask1_28.txt | AC | 112 ms | 35504 KB |
subtask1_29.txt | AC | 117 ms | 35664 KB |
subtask2_01.txt | AC | 111 ms | 35460 KB |
subtask2_02.txt | AC | 107 ms | 35288 KB |
subtask2_03.txt | AC | 109 ms | 35320 KB |
subtask2_04.txt | AC | 99 ms | 34864 KB |
subtask2_05.txt | AC | 103 ms | 35380 KB |
subtask2_06.txt | AC | 107 ms | 35256 KB |
subtask2_07.txt | AC | 114 ms | 35276 KB |
subtask2_08.txt | AC | 110 ms | 35068 KB |
subtask2_09.txt | AC | 108 ms | 35348 KB |
subtask2_10.txt | AC | 106 ms | 35476 KB |
subtask2_11.txt | AC | 98 ms | 35544 KB |
subtask2_12.txt | AC | 103 ms | 35384 KB |
subtask2_13.txt | AC | 102 ms | 34976 KB |
subtask2_14.txt | AC | 96 ms | 34916 KB |
subtask2_15.txt | AC | 113 ms | 35744 KB |
subtask2_16.txt | AC | 108 ms | 35772 KB |
subtask2_17.txt | AC | 111 ms | 35240 KB |
subtask2_18.txt | AC | 109 ms | 35532 KB |
subtask2_19.txt | AC | 108 ms | 35780 KB |
subtask2_20.txt | AC | 110 ms | 35468 KB |
subtask2_21.txt | AC | 117 ms | 35576 KB |
subtask2_22.txt | AC | 106 ms | 35556 KB |
subtask2_23.txt | AC | 107 ms | 35316 KB |
subtask2_24.txt | AC | 112 ms | 35584 KB |
subtask2_25.txt | AC | 110 ms | 35344 KB |
subtask2_26.txt | AC | 108 ms | 35448 KB |
subtask2_27.txt | AC | 116 ms | 35628 KB |
subtask2_28.txt | AC | 114 ms | 35660 KB |
subtask2_29.txt | AC | 108 ms | 35516 KB |