QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510537#8521. Pattern Search IIUNos_mariconesWA 0ms3796kbC++202.7kb2024-08-09 09:03:532024-08-09 09:03:57

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 09:03:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2024-08-09 09:03:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back

typedef long long ll;
typedef long double lf;
typedef pair <ll,ll> pii;

const ll N = 3e5 + 5;
const ll S = 2010;
const ll LOG_N = 18;
const ll oo = 1e16+7;
const ll mod = 2e9 + 7;

int LM = 200;

int main () {
        
  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif

  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int t = 1;
  //cin >> t;
  while (t--) { 
    string s; cin >> s;
    int n = s.size();

    vector <vector<ll>> mx(n + 1, vector<ll>(LM));
    vector <vector<ll>> mn(n + 1, vector<ll>(LM));
    vector <vector<ll>> sz_l (n + 1, vector<ll>(LM));
    vector <vector<ll>> sz_r (n + 1, vector<ll>(LM));

    vector <ll> fib(LM);

    fib[0] = fib[1] = 1;
    for (int i = 2; i < LM; ++i) fib[i] = fib[i - 1] + fib[i - 2];

    for (int w = 0; w < LM; ++w) 
      mx[n][w] = n, mn[0][w] = 0;

    for (int w = 0; w < LM; ++w) { 
      for (int i = 0; i < n; ++i) { 
        if (w == 0) { 
          mx[i][w] = (s[i] == 'b' ? i + 1 : i);
          mn[i + 1][w] = (s[i] == 'b' ? i : i + 1);
        }
        else if (w == 1) { 
          mx[i][w] = (s[i] == 'a' ? i + 1 : i);
          mn[i + 1][w] = (s[i] == 'a' ? i : i + 1);
        }
        else {
          mx[i][w] = mx[mx[i][w - 1]][w - 2];
          mn[i + 1][w] = mn[mn[i + 1][w - 2]][w - 1];
        }

      }
    }

    for (int w = 0; w < LM; ++w) { 
      for (int i = 0; i < n; ++i) { 
          if (w == 0) { 
            if (s[i] == 'b' && i == n - 1) sz_l[i][w] = 1;
            else sz_l[i][w] = oo;

            if (s[i] == 'b' && i == 0) sz_r[i + 1][w] = 1;
            else sz_r[i + 1][w] = oo;
          }
          else if (w == 1) { 
            if (s[i] == 'a' && i == n - 1) sz_l[i][w] = 1;
            else sz_l[i][w] = oo;

            if (s[i] == 'a' && i == 0) sz_r[i + 1][w] = 1;
            else sz_r[i + 1][w] = oo;
          }
          else {
            if (mx[i][w - 1] == n) sz_l[i][w] = sz_l[i][w - 1];
            else sz_l[i][w] = fib[w - 1] + sz_l[mx[i][w - 1]][w - 2];

            if (mn[i + 1][w - 2] == 0) sz_r[i + 1][w] = sz_r[i + 1][w - 2];
            else sz_r[i + 1][w] = fib[w - 2] + sz_r[mn[i + 1][w - 2]][w - 1];
          }

      }
    }

    ll ans = oo;
    for (int w = 0; w < LM; ++w) { 
      if (mx[0][w] == n) { 
        if (w == 0 || w == 1) {
          cout << 1 << '\n';
          break;
        }
        for (int j = 1; j < n; ++j) {
          if (mx[0][w - 1] >= j && mx[j][w - 2] >= n) { 
            ans = min(ans, sz_l[j][w - 2] + sz_r[j][w - 1]);
          }
        }
      }
    }
    cout << ans << '\n';

  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3796kb

input:

a

output:

1
10000000000000008

result:

wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements