Submission #1549714
Source Code Expand
import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main{
static long mod=1000000007;
static int dx[]={1,-1,0,0};
static int dy[]={0,0,1,-1};
// static int dx[]={1,-1,0,0,1,1,-1,-1};
// static int dy[]={0,0,1,-1,1,-1,1,-1};
// PriorityQueue<Integer> que = new PriorityQueue<Integer>();
//HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
public static void main(String[] args) throws Exception, IOException{
Reader sc = new Reader(System.in);
PrintWriter out=new PrintWriter(System.out);
// int n=sc.nextInt();
int n;
char c[]=sc.nextString().toCharArray();
n=c.length;
int d[][]=new int[26][n];
long ans=0;
d[c[0]-'a'][0]++;
for (int i=1; i<n; i++) {
ans+=i-d[c[i]-'a'][i-1];
db(i-d[c[i]-'a'][i-1]);
for (int t=0;t<26 ;t++ ) {
d[t][i]=d[t][i-1];
}
d[c[i]-'a'][i]++;
}
out.println(ans+1);
out.flush();
}
static boolean dfs(boolean w[][],boolean d[],int cur){
for (int i=0; i<d.length; i++) {
if(w[cur][i] && !d[i]){
d[i]=true;
if(cur==d.length-1)return true;
if(!dfs(w,d,cur+1))return false;
d[i]=false;
}
}
return true;
}
static void db(Object... os){
System.err.println(Arrays.deepToString(os));
}
static boolean validpos(int x,int y,int r, int c){
return x<r && 0<=x && y<c && 0<=y;
}
static boolean bit(long x,int k){
// weather k-th bit (from right) be one or zero
return ( 0 < ( (x>>k) & 1 ) ) ? true:false;
}
}
class XY {
int x,y,d;
XY(int x, int y, int d) {
this.x=x;
this.y=y;
this.d=d;
}
}
class P implements Comparable<P>{
int x,y;
P(int x, int y) {
this.x=x;
this.y=y;
}
public int compareTo(P p){
return x - p.x;
}
}
class Reader
{
private BufferedReader x;
private StringTokenizer st;
public Reader(InputStream in)
{
x = new BufferedReader(new InputStreamReader(in));
st = null;
}
public String nextString() throws IOException
{
while( st==null || !st.hasMoreTokens() )
st = new StringTokenizer(x.readLine());
return st.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(nextString());
}
public long nextLong() throws IOException
{
return Long.parseLong(nextString());
}
public double nextDouble() throws IOException
{
return Double.parseDouble(nextString());
}
}
Submission Info
Submission Time |
|
Task |
B - Reverse and Compare |
User |
mukku |
Language |
Java8 (OpenJDK 1.8.0) |
Score |
500 |
Code Size |
2935 Byte |
Status |
AC |
Exec Time |
780 ms |
Memory |
93784 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
68 ms |
20692 KB |
sample_02.txt |
AC |
67 ms |
23124 KB |
sample_03.txt |
AC |
71 ms |
21076 KB |
subtask_1_01.txt |
AC |
68 ms |
21076 KB |
subtask_1_02.txt |
AC |
716 ms |
91216 KB |
subtask_1_03.txt |
AC |
68 ms |
21076 KB |
subtask_1_04.txt |
AC |
68 ms |
21076 KB |
subtask_1_05.txt |
AC |
76 ms |
15828 KB |
subtask_1_06.txt |
AC |
123 ms |
19284 KB |
subtask_1_07.txt |
AC |
209 ms |
37428 KB |
subtask_1_08.txt |
AC |
676 ms |
86720 KB |
subtask_1_09.txt |
AC |
690 ms |
83920 KB |
subtask_1_10.txt |
AC |
686 ms |
89268 KB |
subtask_1_11.txt |
AC |
672 ms |
84944 KB |
subtask_1_12.txt |
AC |
682 ms |
87148 KB |
subtask_1_13.txt |
AC |
780 ms |
93784 KB |
subtask_1_14.txt |
AC |
627 ms |
85768 KB |
subtask_1_15.txt |
AC |
706 ms |
86336 KB |
subtask_1_16.txt |
AC |
740 ms |
89424 KB |
subtask_1_17.txt |
AC |
756 ms |
87744 KB |