Submission #1540289


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;

int counts[30][200002];

int main(){
    string A;
    cin >> A;

    memset(counts, 0, sizeof(counts));
    int N = A.size();
    for(int i=0;i<26;i++){
        char c = 'a' + i;
        int v = 0;
        for(int j=N-1;j>=0;j--){
            counts[i][j] = v;
            if(A[j] == c){
                v++;
            }
        }
    }

    ll ans = 0;
    for(int i=0;i<N;i++){
        ans += N - 1 - i - counts[int(A[i] - 'a')][i];
    }
    cout << 1 + ans << endl;

    return 0;
}

Submission Info

Submission Time
Task B - Reverse and Compare
User zaburo
Language C++14 (GCC 5.4.1)
Score 500
Code Size 641 Byte
Status
Exec Time 21 ms
Memory 24068 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 500 / 500 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 7 ms 23680 KB
sample_02.txt 7 ms 23680 KB
sample_03.txt 7 ms 23680 KB
subtask_1_01.txt 7 ms 23680 KB
subtask_1_02.txt 20 ms 23940 KB
subtask_1_03.txt 7 ms 23680 KB
subtask_1_04.txt 7 ms 23680 KB
subtask_1_05.txt 7 ms 23680 KB
subtask_1_06.txt 7 ms 23680 KB
subtask_1_07.txt 8 ms 23680 KB
subtask_1_08.txt 21 ms 23940 KB
subtask_1_09.txt 21 ms 23940 KB
subtask_1_10.txt 21 ms 24068 KB
subtask_1_11.txt 21 ms 23940 KB
subtask_1_12.txt 21 ms 23940 KB
subtask_1_13.txt 21 ms 24068 KB
subtask_1_14.txt 21 ms 23940 KB
subtask_1_15.txt 21 ms 24068 KB
subtask_1_16.txt 21 ms 23940 KB
subtask_1_17.txt 21 ms 24068 KB