結果

問題 No.341 沈黙の期間
ユーザー antaanta
提出日時 2016-02-12 23:34:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 3,147 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 89,508 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 03:35:39
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }


unsigned errorUTF8Char(unsigned char leadingByte) {
	return 0xdc00U + leadingByte;
}

template<typename It>
unsigned decodeUTF8Char(It &it) {
	unsigned char lb = *it; ++ it;	//leading byte
	int len;
	if((lb & 0x80) == 0) len = 1;
	else if((lb & 0xe0) == 0xc0) len = 2;
	else if((lb & 0xf0) == 0xe0) len = 3;
	else if((lb & 0xf8) == 0xf0) len = 4;
	else if((lb & 0xfc) == 0xf8) len = 5;
	else if((lb & 0xfe) == 0xfc) len = 6;
	else return errorUTF8Char(lb);
	unsigned code = len == 1 ? lb : lb & ((1 << (7 - len)) - 1);
	for(int i = 1; i < len; ++ i) {
		unsigned char byte = *it; ++ it;
		if((byte & 0xc0) != 0x80) {
			for(; i >= 1; -- i) -- it;
			return errorUTF8Char(lb);
		}
		code = code << 6 | (byte & ~0x80U);
	}
	return code;
}

template<typename It>
int encodeUTF8Char(unsigned code, It &it) {
	int len;
	if(code <= 0x7fU) len = 1;
	else if(code <= 0x7ffU) len = 2;
	else if(code <= 0xffffU) len = 3;
	else if(code <= 0x1fffffU) len = 4;
	else if(code <= 0x3ffffffU) len = 5;
	else if(code <= 0x7fffffffU) len = 6;
	else return -1;	//error
	unsigned char lb = (unsigned char)(code >> ((len - 1) * 6));
	if(len > 1) lb |= (unsigned char)(0xffU << (8 - len));
	*it = lb; ++ it;
	for(int i = 1; i < len; ++ i) {
		*it = (unsigned char)(0x80 | (code >> ((len - 1 - i) * 6) & 0x3f));
		++ it;
	}
	return len;
}

template<typename T>
vector<pair<T, int> > runLength(const T a[], int n) {
	vector<pair<T, int> > r;
	if(n <= 0) return r;
	int cnt = 0;
	for(int i = 0; i <= n; i ++) {
		if(i == n || (i != 0 && a[i] != a[i - 1])) {
			r.push_back(make_pair(a[i - 1], cnt));
			cnt = 0;
		}
		cnt ++;
	}
	return r;
}

int main() {
	string encoded;
	while(cin >> encoded) {
		vector<unsigned> S;
		for(const char *p = encoded.c_str(); *p; )
			S.push_back(decodeUTF8Char(p));
		auto runs = runLength(S.data(), S.size());
		int maxNum = 0;
		rep(i, runs.size()) {
			if(runs[i].first == u'…')
				amax(maxNum, runs[i].second);
		}
		printf("%d\n", maxNum);
	}
	return 0;
}
0