QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#447382 | #8521. Pattern Search II | ucup-team3877 | WA | 0ms | 3620kb | C++20 | 1.3kb | 2024-06-18 12:11:27 | 2024-06-18 12:11:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.size(), m = 32;
vector<vector<int>> v(m,vector<int>(n+1)), dp(m,vector<int>(n+1,INF));
vector<int> c(m,0);
rep(i,m) v[i][n] = n;
c[0] = c[1] = 1;
rep(i,n){
v[0][i] = i + (s[i]=='b');
v[1][i] = i + (s[i]=='a');
}
for(int i=2;i<m;++i){
rep(j,n){
v[i][j] = v[i-2][v[i-1][j]];
}
c[i] = c[i-1] + c[i-2];
}
rep(i,m) dp[i][v[i][0]] = c[i];
int ans = INF;
rep(i,n){
rep(j,m){
rep(k,m){
if(!(j&1)&&!(k&1)) continue;
chmin(dp[k][v[k][i]], dp[j][i]+c[k]);
}
}
}
rep(i,m) chmin(ans, dp[i][n]);
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
bbba
output:
6
result:
wrong answer 1st numbers differ - expected: '7', found: '6'