Submission #20386817
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define precision cout << fixed << setprecision(15);
const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t time_p = clock();
void ktj() {
time_p = clock() - time_p;
cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
void pre() {}
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool f = 1; string r = "{";
for (const auto &x : v) { if (!f) r += ", "; f = 0; r += to_string(x); }
return r + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H); debug_out(T...);
}
#ifdef LOCAL
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define pr(...) 42
#endif
void solve() {
string s;
cin >> s;
vector<int> cnt(26, 0);
int n = s.size();
cnt[s[n - 1] - 'a'] = 1;
long long ans = 0;
for (int i = n - 3; i >= 0; i--) {
if (s[i] == s[i + 1]) {
long long curr = 0;
curr += (n - 1) - (i + 1);
curr -= cnt[s[i] - 'a'];
for (int j = 0; j < 26; j++) {
if (j != s[i] - 'a')
cnt[j] = 0;
}
cnt[s[i] - 'a'] += curr;
ans += curr;
}
cnt[s[i + 1] - 'a'] += 1;
}
cout << ans << '\n';
}
#define GOOGLE 0
#define MULTIPLE_TC 0
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
pre();
int t = 1, T;
if (MULTIPLE_TC)
cin >> t;
for (T = 1; T <= t; T++) {
if (GOOGLE)
cout << "Case #" << T << ": ";
solve();
}
ktj();
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - String Invasion |
| User | kshitij_07 |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 2396 Byte |
| Status | AC |
| Exec Time | 19 ms |
| Memory | 3972 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| 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, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 9 ms | 3920 KiB |
| 02.txt | AC | 4 ms | 3876 KiB |
| 03.txt | AC | 6 ms | 3812 KiB |
| 04.txt | AC | 7 ms | 3812 KiB |
| 05.txt | AC | 13 ms | 3876 KiB |
| 06.txt | AC | 9 ms | 3824 KiB |
| 07.txt | AC | 7 ms | 3828 KiB |
| 08.txt | AC | 5 ms | 3820 KiB |
| 09.txt | AC | 12 ms | 3816 KiB |
| 10.txt | AC | 16 ms | 3812 KiB |
| 11.txt | AC | 7 ms | 3828 KiB |
| 12.txt | AC | 5 ms | 3816 KiB |
| 13.txt | AC | 4 ms | 3876 KiB |
| 14.txt | AC | 19 ms | 3920 KiB |
| 15.txt | AC | 13 ms | 3972 KiB |
| 16.txt | AC | 14 ms | 3832 KiB |
| 17.txt | AC | 16 ms | 3924 KiB |
| 18.txt | AC | 16 ms | 3820 KiB |
| 19.txt | AC | 2 ms | 3704 KiB |
| 20.txt | AC | 3 ms | 3740 KiB |
| 21.txt | AC | 2 ms | 3740 KiB |
| 22.txt | AC | 3 ms | 3684 KiB |
| s1.txt | AC | 3 ms | 3760 KiB |
| s2.txt | AC | 2 ms | 3680 KiB |
| s3.txt | AC | 2 ms | 3700 KiB |