Submission #7858734


Source Code Expand

Copy
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 200031;

string st;
long long k;

bool all_same(string st){
	for (int i=1;i<st.size();i++)
		if(st[i]!=st[i-1])
			return false;
	return true;
}

long long ans;

long long solver(long long x){
	if (x%2==0)
		return x/2;
	return (x-1)/2;
}

long long special_case(){
	return solver(st.size()*1ll*k);
}

vector<pair<int,int> > decouple(string st){
	vector<pair<int,int > > ret;
	int cnt=0;
	for (int i=0;i<st.size();i++){
		if (i>0&&st[i]!=st[i-1]){
			ret.push_back(make_pair(st[i-1],cnt));
			cnt=0;
		}
		++cnt;
	}
	ret.push_back(make_pair(st[st.size()-1],cnt));
	return ret;
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
 //   freopen("input.txt", "r", stdin);
 //   freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
 //   cin.tie(0);

    cin>>st>>k;

    if (all_same(st)){
    	cout<<special_case()<<endl;
    	return 0;
    }

    vector<pair<int,int> > V=decouple(st);

    for (int i=1;i+1<V.size();i++){
    	ans+=solver(V[i].second)*k;
    }

    ans+=solver(V[0].second);
    ans+=solver(V.back().second);

    if (V[0].first==V.back().first)
    	ans+=solver(V[0].second+V.back().second)*(k-1);
    else
    {
    	ans+=solver(V[0].second)*k;
    	ans+=solver(V.back().second)*k;
    }

    cout<<ans<<endl;

//    cin.get(); cin.get();
    return 0;
}

Submission Info

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

Compile Error

./Main.cpp:38:0: warning: "M_PI" redefined
 #define M_PI 3.141592653589793
 ^
In file included from /usr/include/c++/5/cmath:44:0,
                 from /usr/include/c++/5/complex:44,
                 from ./Main.cpp:9:
/usr/include/math.h:372:0: note: this is the location of the previous definition
 # define M_PI  3.14159265358979323846 /* pi */
 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 11
WA × 4
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 WA 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 WA 1 ms 256 KB
10.txt WA 1 ms 256 KB
11.txt AC 1 ms 256 KB
12.txt WA 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