QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107595#3286. Black or Whitessk4988WA 17ms8936kbC++142.6kb2023-05-22 07:28:252023-05-22 07:28:27

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-22 07:28:27]
  • Judged
  • Verdict: WA
  • Time: 17ms
  • Memory: 8936kb
  • [2023-05-22 07:28:25]
  • Submitted

answer

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

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<ld>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
using vvi = vector<vi>;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define nL "\n"

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int n, k; cin >> n >> k;
    string s1, s2; cin >> s1 >> s2;
    vi v1(n), v2(n), pref2(n);
    deque<pi> dq; // {color, start}
    int ans = 0;
    vi qs;
    rep(i, 0, n){
        v1[i] = s1[i] == 'B';
        pref2[i] = v2[i] = s2[i] == 'B';
        if(i) pref2[i] += pref2[i - 1];
        if(v1[i] != v2[i]){
            qs.pb(i);
        }
    }
    auto pref = [&](int l, int r)->int{
        int val = pref2[r];
        if(l >= 0) val -= pref2[l];
        return val;
    };
    vi covered(n);
    rep(i, 0, n){
        if(covered[i]) continue;
        if(v1[i] != v2[i]){
            for(int j = i - 1; j >= 0 && !covered[j] && v2[j] == v2[i]; j--){
                covered[j] = true;
            }
            for(int j = i; j < n && !covered[j] && v2[j] == v2[i]; j++){
                covered[j] = true;
            }
        }
    }
    int pre = -1;
    vi places;
    rep(i, 0, n){
        if(v2[i] == v1[i]){
            while(!covered[i] && sz(dq) && dq.back().f != v2[i]) dq.pop_back();
            continue;
        }
        assert(sz(dq) <= 2);
        rep(j, 0, sz(dq)){
            if(dq[j].s + k <= i){
                if(j == 0) dq.pop_front();
                else dq.pop_back();
                j--;
            }
        }
        if(sz(dq) == 0){
            ans++;
            dq.pb({v2[i], i});

        }
        else if(v2[i] == dq.back().f){
            if(pref(dq.back().s, i) == (i - dq.back().s) * v2[i]){
                // same color so far so extend
            }
            else{
                ans++;
                dq.pop_back();
                dq.pb({v2[i], i});
            }
        }
        else{
            if(sz(dq) == 1){
                ans++;
                dq.pb({v2[i], i});
            }
            else if(sz(dq) == 2){
                dq.pop_back();
                // extended dq[0]
            }
            else{
                assert(false);
            }
        }
        pre = i;
    }
    cout << ans << "\n";
    
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 8936kb

input:

274694 5174
BBWWWWWBWBBBWBWBWBWBBBBWWBBBBBWWBWWBWWBBWBWWBBBWWWWWBWBBBBWWBBBWWBWWBBWBBWWBBWWBWWBBWWWWBWBBWBBBWBWBWBBBBWBWWWBWWWBBWBBWWWWBWWWWBBBWBWWBWBBBWBBWWWWBBWBBBWBWBBBBWBBBBBWBBWWBWBBBBWBWWWWWBWBBBBWWWWBBWWWBWBWBWWWBWWBBBBWBBWBWBBWWWWBBBWBBBWBWWBWWBBBWWWWBBWWWBBBWWBWWWBBWBBBWBBBBWBWWBWBWBBBBBBWW...

output:

72592

result:

wrong answer 1st lines differ - expected: '63250', found: '72592'