COFO::1415C Bouncing Ball

Problem

Point

Design

Big O(time)

Code

#define rep(i, a, b) for(int i = (a); i<(b); i++)
#define r_rep(i, a, b) for(int i=(a); i>(b); i--)
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


string s;
int x, y;
int n, p, k;
int mn;
void input(){
    mn = 1000000001; // p = 100000이고 y 가 10000 인경우 max
    cin >> n >> p >> k >> s >> x >> y;
}
void solve(){
    input();
    p -= 1;
    rep(i, 0, k+1){
        int st = p + i;
        string tmp = "";
        int cur = st;
        int cnt0 = 0, cnt1 = 0;
        while(cur < n){
            if(s[cur] == '1') cnt1++;
            else cnt0++;
            tmp += s[cur];
            cur += k;
        }
        cur = 0;
        int cntDel = i;
        while(cur < (int)tmp.size()){
            int sum = cnt0 * x + y * cntDel;
            mn = min(mn, sum);
            cntDel += k;
            if(tmp[cur] == '0') cnt0--;
            cur += 1;
        }
    }
    cout << mn << '\n';
}
int main(){;
    //freopen("input.txt", "r", stdin);
    int tc; cin >> tc;
    while(tc--)
        solve();
    return 0;
}