Submission #1694213


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

string s;

int main(){
    cin >> s;
    int n = s.size();

    vector<char> p(n),q(n);
    rep(i,n){
        if(i%2==0){
            p[i]='2';q[i]='5';
        }else{
            p[i]='5';q[i]='2';
        }
    }

    vector<int> ps(n,0),qs(n,0);
    rep(i,n)
        if(s[i]==p[i] or s[i]=='?') ps[i]=1;
        else ps[i]=0;

    rep(i,n)
        if(s[i]==q[i] or s[i]=='?') qs[i]=1;
        else qs[i]=0;

    //cout << ps << endl;
    //cout << qs << endl;

    int l,r;
    l=r=0;

    //cout << p << endl;

    int ans1 = 0;
    while(l<n){
        //cout << l << " " << (l<n) << " " << (ps[l]==0) << " " << (p[l]!='2') << endl;
        while(l<n and (ps[l]==0 or p[l]!='2')){
            l++;
        }
        r=l+1;
        while(r<n and ps[r]==1) r++;
        ans1 = max(ans1,(r-l)/2*2);
        //cerr << l << " " << r << endl;
        l=r;
    }

    l=r=0;
    int ans2=0;
    while(l<n){
        //cout << l << " " << (l<n) << " " << (qs[l]==0) << " " << (q[l]!='2') << endl;
        while(l<n and (qs[l]==0 or q[l]!='2')){
            l++;
        }
        r=l+1;
        while(r<n and qs[r]==1) r++;
        ans1 = max(ans1,(r-l)/2*2);
        //cerr << l << " " << r << endl;
        l=r;
    }

    //cerr << ans1 << " " << ans2 << endl;
    cout << max(ans1,ans2)<< endl;
}

Submission Info

Submission Time
Task B - ニコニコレベル
User chakku000
Language C++14 (GCC 5.4.1)
Score 300
Code Size 3034 Byte
Status AC
Exec Time 7 ms
Memory 1408 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 5
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All 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, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
hand_01.txt AC 1 ms 256 KB
hand_02.txt AC 1 ms 256 KB
hand_03.txt AC 1 ms 256 KB
hand_04.txt AC 1 ms 256 KB
hand_05.txt AC 5 ms 1408 KB
large_01.txt AC 7 ms 1408 KB
large_02.txt AC 7 ms 1408 KB
large_03.txt AC 7 ms 1408 KB
random_01.txt AC 7 ms 1408 KB
random_02.txt AC 6 ms 1408 KB
random_03.txt AC 6 ms 1408 KB
random_04.txt AC 7 ms 1408 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
sample_05.txt AC 1 ms 256 KB