QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455934#8521. Pattern Search IIUSP_USP_USPWA 1ms5692kbC++201.9kb2024-06-27 02:30:282024-06-27 02:30:29

Judging History

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

  • [2024-06-27 02:30:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-06-27 02:30:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
using ll = long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 2e5 + 5;
const int MOD = 1e9+7; //998244353;
const int INF = 0x3f3f3f3f;
const ll INF64 = ll(4e18) + 5;


int dp[MAXN][2][2];

void solve(){
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				dp[i][j][k] = INF;
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				for(int w = 0; w < 2; w++){
					if(j == k && k == w) continue;
					if(i == 0 && s[0] == 'b'){
						dp[1][k][w] = min(dp[1][k][w],1ll);
					}
					string pat;
					if(w == 0){
						pat = "aab";
					}else{
						pat = "ab"; 
					}
					int nx = i;
					int sz = pat.size();
					int cnt = 0;
					for(auto c : pat){
						cnt++;
						if(nx < n && s[nx] == c){
							nx++;
						}
						if(nx == n){
							dp[nx][k][w] = min(dp[nx][k][w],dp[i][j][k]+cnt);
						}
					}
					dp[nx][k][w] = min(dp[nx][k][w],dp[i][j][k]+sz);

				}
			}
		}
	}
	int ans = INF;
	for(int i = 0; i < 2; i++){	
		for(int j = 0; j < 2; j++){
			ans = min(ans,dp[n][i][j]);
		}
	}
	cout << ans << '\n';

}

signed main(){

    ios::sync_with_stdio(false); cin.tie(NULL);

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}

/*
Makefile:
CXXFLAGS=-Wall -Wextra -Wshadow -g -pedantic -fsanitize=address,undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUGPEDANTIC -std=gnu++17
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5692kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

bbba

output:

6

result:

wrong answer 1st numbers differ - expected: '7', found: '6'