第3回 ドワンゴからの挑戦状 予選

Submission #1051725

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  string s;
  cin >> s;
  int len = s.length();
  deque<bool> mb2_even(len+1, false), mb2_odd(len+1, false), mb5_even(len, false), mb5_odd(len, false);
  rep (i, len) {
    if (s[i] == '2' || s[i] == '?') {
      if (i % 2 == 0) {
        mb2_even[i] = true;
        mb2_even[i+1] = true;
      } else {
        mb2_odd[i] = true;
        mb2_odd[i+1] = true;
      }
    }
  }
  FOR (i, 1, len) {
    if (s[i] == '5' || s[i] == '?') {
      if (i % 2 == 0) {
        mb5_even[i] = true;
        mb5_even[i-1] = true;
      } else {
        mb5_odd[i] = true;
        mb5_odd[i-1] = true;
      }
    }
  }

  deque<bool> mb_even(len, false), mb_odd(len, false);
  rep (i, len) {
    mb_even[i] = (mb2_even[i] && mb5_odd[i]);
    mb_odd[i] = (mb2_odd[i] && mb5_even[i]);
  }

  int ans = 0;
  int index;
  index = 0;
  while (index < len) {
    if (mb_even[index]) {
      rep (i, len-index) {
        if (!mb_even[i + index]) {
          ans = max(ans, i);
          index += i;
          break;
        } else if (i == len-index-1) {
          ans = max(ans, i+1);
          index = len;
          break;
        }
      }
    } else {
      index += 1;
    }
  }

  index = 0;
  while (index < len) {
    if (mb_odd[index]) {
      rep (i, len-index) {
        if (!mb_odd[i + index]) {
          ans = max(ans, i);
          index += i;
          break;
        } else if (i == len-index-1) {
          ans = max(ans, i+1);
          index = len;
          break;
        }
      }
    } else {
      index += 1;
    }
  }

  printf("%d\n", ans);

  return 0;
}

Submission

Task問題 B - ニコニコレベル
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 300
Source lengthソースコード長 2622 Byte
File nameファイル名
Exec time実行時間 12 ms
Memory usageメモリ使用量 960 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_05.txt
All 300 / 300 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_05.txt,hand_01.txt,hand_02.txt,hand_03.txt,hand_04.txt,hand_05.txt,large_01.txt,large_02.txt,large_03.txt,random_01.txt,random_02.txt,random_03.txt,random_04.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
hand_01.txt AC 3 ms 256 KB
hand_02.txt AC 3 ms 256 KB
hand_03.txt AC 3 ms 256 KB
hand_04.txt AC 3 ms 256 KB
hand_05.txt AC 10 ms 960 KB
large_01.txt AC 11 ms 960 KB
large_02.txt AC 11 ms 960 KB
large_03.txt AC 11 ms 960 KB
random_01.txt AC 12 ms 960 KB
random_02.txt AC 12 ms 960 KB
random_03.txt AC 11 ms 960 KB
random_04.txt AC 12 ms 960 KB
sample_01.txt AC 3 ms 256 KB
sample_02.txt AC 3 ms 256 KB
sample_03.txt AC 3 ms 256 KB
sample_04.txt AC 3 ms 256 KB
sample_05.txt AC 3 ms 256 KB