Submission #15575374


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s;
	cin >> s;
	
	int n = (int)s.size();
	vector<int> sum(n + 1, 0);
	map<int, int> mp;
	
	for(int i = 0; i < n; ++i) {
		sum[i + 1] += sum[i];
		
		if( s.substr(i, 2) == "25" ) sum[i + 1]++;
		if( sum[i + 1] > 0 ) mp[sum[i + 1]]++;
	}
	
	if( mp.empty() ) {
		cout << 0 << endl;
		return 0;
	}
	
	int ans = 0;
	int cnt = 0;
	
	bool flag = false;
	
	for(auto& x : mp) {
		if( x.second == 2 ) {
			cnt++;
			flag = true;
		} else {
			if( cnt > 1 ) {
				ans += cnt * (cnt + 1) / 2;
			} else {
				ans++;
			}			
			
			flag = false;
			cnt = 0;
		}
	}
	
	if( flag ) ans += cnt * (cnt + 1) / 2;
	
	cout << ans << endl;
	
	return 0;
}

Submission Info

Submission Time
Task B - ニコニコ文字列
User orieka
Language C++ (GCC 9.2.1)
Score 0
Code Size 1067 Byte
Status
Exec Time 27 ms
Memory 6040 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask0_sample_05.txt
Subtask1 0 / 30 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask0_sample_05.txt
All 0 / 70 subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask0_sample_05.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt 6 ms 3600 KB
subtask0_sample_02.txt 2 ms 3480 KB
subtask0_sample_03.txt 2 ms 3596 KB
subtask0_sample_04.txt 2 ms 3584 KB
subtask0_sample_05.txt 2 ms 3632 KB
subtask1_01.txt 2 ms 3648 KB
subtask1_02.txt 4 ms 3500 KB
subtask1_03.txt 2 ms 3660 KB
subtask1_04.txt 2 ms 3636 KB
subtask1_05.txt 3 ms 3668 KB
subtask1_06.txt 1 ms 3620 KB
subtask1_07.txt 4 ms 3680 KB
subtask1_08.txt 4 ms 3744 KB
subtask1_09.txt 2 ms 3620 KB
subtask1_10.txt 3 ms 3552 KB
subtask1_11.txt 2 ms 3472 KB
subtask1_12.txt 2 ms 3716 KB
subtask1_13.txt 2 ms 3576 KB
subtask2_01.txt 7 ms 3752 KB
subtask2_02.txt 9 ms 3696 KB
subtask2_03.txt 9 ms 3640 KB
subtask2_04.txt 16 ms 3752 KB
subtask2_05.txt 10 ms 3696 KB
subtask2_06.txt 10 ms 3820 KB
subtask2_07.txt 27 ms 5976 KB
subtask2_08.txt 25 ms 6040 KB
subtask2_09.txt 8 ms 3888 KB
subtask2_10.txt 7 ms 3820 KB
subtask2_11.txt 5 ms 3848 KB
subtask2_12.txt 3 ms 3664 KB