Contest Duration: - (local time) (150 minutes) Back to Home

Submission #7867074

Source Code Expand

Copy
```#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll k;
string s;

void solve(){
cin >> s;
cin >> k;
int n=s.length();
ll l=1;
vector<ll> vec;
Rep(i,1,n){
if (s[i]==s[i-1]){
l++;
}
else{
vec.push_back(l);
l=1;
}
}
vec.push_back(l);
int m=vec.size();
if (m==1){
cout << n*k/2 << endl;
return;
}
ll ans=0;
if (s[0]==s[n-1]){
ans+=vec[0]/2+vec[m-1]/2;
ans+=(k-1)*((vec[0]+vec[m-1])/2);
Rep(i,1,m-1){
ans+=k*(vec[i]/2);
}
}
else{
rep(i,m){

ans+=k*(vec[i]/2);
}
}
cout << ans << endl;

}

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
}```

#### Submission Info

Submission Time 2019-10-05 21:57:04+0900 A - Connection and Disconnection Chanyuh C++14 (GCC 5.4.1) 300 1815 Byte AC 1 ms 256 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
 AC × 3
 AC × 15
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, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 1 ms 256 KB
12.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB