Submission #7860136


Source Code Expand

Copy
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<int> G;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	string s;
	int K, cnt=1;
	long long ans=0;
	cin>>s>>K;
	for(int i=1;i<s.size();i++) {
		if(s[i]!=s[i-1]) {
			G.push_back(cnt);
			cnt=1;
		}
		else cnt++;
	}
	G.push_back(cnt);
	if(G.size()==1) {
		cout<<G[0]/2LL*K<<'\n';
		return 0;
	}
	if(s[0]==s.back()) {
		ans=G[0]/2+G.back()/2;
		G[0]+=G.back();
		G.pop_back();
		ans+=G[0]/2LL*(K-1LL);
		for(int i=1;i<G.size();i++) if(G[i]>1) ans+=G[i]/2LL*K;
	}
	else for(auto g: G) ans+=g/2LL*K;
	cout<<ans<<'\n';
	return 0;
}

Submission Info

Submission Time
Task A - Connection and Disconnection
User Lawali
Language C++14 (GCC 5.4.1)
Score 0
Code Size 890 Byte
Status WA
Exec Time 2 ms
Memory 256 KB

Judge Result

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