QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107593#3286. Black or Whitessk4988WA 4ms8032kbC++142.1kb2023-05-22 07:11:372023-05-22 07:11:39

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:11:39]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 8032kb
  • [2023-05-22 07:11:37]
  • 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;
    };
    int pre = -1;
    for(int i : qs){
        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(pre, i) == (i - pre) * 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: 4ms
memory: 8032kb

input:

274694 5174
BBWWWWWBWBBBWBWBWBWBBBBWWBBBBBWWBWWBWWBBWBWWBBBWWWWWBWBBBBWWBBBWWBWWBBWBBWWBBWWBWWBBWWWWBWBBWBBBWBWBWBBBBWBWWWBWWWBBWBBWWWWBWWWWBBBWBWWBWBBBWBBWWWWBBWBBBWBWBBBBWBBBBBWBBWWBWBBBBWBWWWWWBWBBBBWWWWBBWWWBWBWBWWWBWWBBBBWBBWBWBBWWWWBBBWBBBWBWWBWWBBBWWWWBBWWWBBBWWBWWWBBWBBBWBBBBWBWWBWBWBBBBBBWW...

output:

57115

result:

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