Submission #15578653


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define int long long

signed main() {
  string s;
  cin >> s;

  int n = s.size();
  vector<int> cnt(n + 1);

  for (int i = 0; i < n;) {
    if(s[i] == '2') {
      int length = 0;
      if(i == n - 1) break;
      for (int j = i + 1; j < n; j++) {
        if(j % 2 != i % 2 && s[j] == '5') {
          length++;
          if(j == n - 1) {
            cnt[length]++;
            i = j;
            break;
          }
        } else if(j % 2 == i % 2 && s[j] == '2') {
          if(j == n - 1) {
            cnt[length]++;
            i = j;
            break;
          }
        } else {
          cnt[length]++;
          i = j;
          break;
        }
      }
    } else {
      i++;
    }
  }
  int answer = 0;
  for (int i = 1; i <= n; i++) {
    answer += cnt[i] * (i + 1) * i / 2LL;
  }
  cout << answer << endl;
  return 0;
}

Submission Info

Submission Time
Task B - ニコニコ文字列
User Jonah00
Language C++ (GCC 9.2.1)
Score 100
Code Size 982 Byte
Status
Exec Time 15 ms
Memory 4304 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 30 / 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 70 / 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 8 ms 3480 KB
subtask0_sample_02.txt 4 ms 3480 KB
subtask0_sample_03.txt 2 ms 3564 KB
subtask0_sample_04.txt 3 ms 3640 KB
subtask0_sample_05.txt 5 ms 3560 KB
subtask1_01.txt 2 ms 3640 KB
subtask1_02.txt 1 ms 3588 KB
subtask1_03.txt 2 ms 3640 KB
subtask1_04.txt 2 ms 3544 KB
subtask1_05.txt 1 ms 3592 KB
subtask1_06.txt 2 ms 3628 KB
subtask1_07.txt 2 ms 3544 KB
subtask1_08.txt 2 ms 3492 KB
subtask1_09.txt 2 ms 3596 KB
subtask1_10.txt 2 ms 3588 KB
subtask1_11.txt 2 ms 3444 KB
subtask1_12.txt 2 ms 3636 KB
subtask1_13.txt 2 ms 3444 KB
subtask2_01.txt 7 ms 4244 KB
subtask2_02.txt 7 ms 4156 KB
subtask2_03.txt 15 ms 4192 KB
subtask2_04.txt 8 ms 4304 KB
subtask2_05.txt 6 ms 4204 KB
subtask2_06.txt 12 ms 4304 KB
subtask2_07.txt 11 ms 4220 KB
subtask2_08.txt 7 ms 4252 KB
subtask2_09.txt 2 ms 3576 KB
subtask2_10.txt 3 ms 3716 KB
subtask2_11.txt 2 ms 3648 KB
subtask2_12.txt 2 ms 3572 KB