Submission #2695703
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static String S; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); S = sc.next(); System.out.println( solve() ); } static long solve() { int N = S.length(); long sum = 0; for (int i = 0; i < N; i++) { int k = i + 1; if( k == 1 || k == N ) { sum += N-1; continue; } boolean up = S.charAt(i) == 'U'; int above = N - k; int below = k - 1; if( up ) { sum += above; sum += below * 2; } else { sum += above * 2; sum += below; } } return sum; } 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 | B - Evilator |
User | kusomushi |
Language | Java8 (OpenJDK 1.8.0) |
Score | 400 |
Code Size | 2662 Byte |
Status | AC |
Exec Time | 90 ms |
Memory | 23252 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 89 ms | 22612 KB |
02.txt | AC | 88 ms | 23252 KB |
03.txt | AC | 87 ms | 21204 KB |
04.txt | AC | 90 ms | 21716 KB |
05.txt | AC | 89 ms | 19540 KB |
06.txt | AC | 86 ms | 22228 KB |
07.txt | AC | 88 ms | 19924 KB |
08.txt | AC | 86 ms | 21588 KB |
09.txt | AC | 68 ms | 21204 KB |
10.txt | AC | 68 ms | 22996 KB |
s1.txt | AC | 68 ms | 19028 KB |
s2.txt | AC | 67 ms | 17748 KB |