Submission #6964393


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/













string S;
int N;
int dp[201010][3];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
	N = S.length();
	S += "####";

	rep(i, 0, N + 1) rep(pre, 0, 3) dp[i][pre] = -inf;
	dp[0][0] = 0;

	rep(i, 0, N) rep(pre, 0, 3) rep(d, 1, 3) if (0 <= dp[i][pre]) {
		if (pre == d) {
			if (d == 1) {
				if (S[i - 1] == S[i]) continue;
			}
			else {
				if (S[i - 2] == S[i] and S[i - 1] == S[i + 1]) continue;
			}
		}
		chmax(dp[i + d][d], dp[i][pre] + 1);
	}

	cout << max(dp[N][1], dp[N][2]) << endl;
}






Submission Info

Submission Time
Task A - Dividing a String
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1884 Byte
Status AC
Exec Time 7 ms
Memory 2964 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 23
Set Name Test Cases
Sample sample01.txt, sample02.txt
All sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt AC 6 ms 2964 KB
in02.txt AC 7 ms 2964 KB
in03.txt AC 6 ms 2964 KB
in04.txt AC 6 ms 2964 KB
in05.txt AC 6 ms 2964 KB
in06.txt AC 6 ms 2964 KB
in07.txt AC 7 ms 2964 KB
in08.txt AC 7 ms 2964 KB
in09.txt AC 7 ms 2964 KB
in10.txt AC 7 ms 2964 KB
in11.txt AC 1 ms 256 KB
in12.txt AC 1 ms 256 KB
in13.txt AC 1 ms 256 KB
in14.txt AC 1 ms 256 KB
in15.txt AC 1 ms 256 KB
in16.txt AC 1 ms 256 KB
in17.txt AC 6 ms 2964 KB
in18.txt AC 1 ms 256 KB
in19.txt AC 1 ms 256 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB