QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#954463#10010. Kids And Sequence GameAfterlifeWA 24ms5888kbC++203.6kb2025-03-28 19:35:272025-03-28 19:35:27

Judging History

This is the latest submission verdict.

  • [2025-03-28 19:35:27]
  • Judged
  • Verdict: WA
  • Time: 24ms
  • Memory: 5888kb
  • [2025-03-28 19:35:27]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long 

const int N=50050;
int n,op;
ll a[N];
vector<int> B;
vector<int> c[N];
int all ;
int cnt = 0;
int bad = 0;

void Ins(ll x , int id){
    vector<int> st;
    while(x){
        int c=x&1;
        x>>=1;
        if(!st.empty()&&st.back()==c&&c == 1){
            st.pop_back();
            continue;
        }
        if(st.size() >= 2 && st.back() == c && st[st.size() - 2] == c && c== 0) {
            st.pop_back() ;
            continue ;
        }
        st.push_back(c);
    }
    if(st.empty())return;
    if(st[0] == 1) {
        cnt++ ;
        st.erase(st.begin()) ;
        op ^= 1;
    }
    if(st.size() >= 2 && st[0] == 0 && st[1] == 0) {
        st.erase(st.begin()) ;
        op ^= 1;
    }
    if(st.size() == 1 && st[0] == 0) {
        op ^= 1;
        return ;
    }
    vector<char> v;
    for(int i = 0 ; i < st.size() ;i ++) {
        if(i + 2 < st.size() && st[i + 2] == 0 && (i + 3 == st.size() || st[i + 3] == 0)) {v.push_back('B') ; i += 2;}
        else {v.push_back('A') ; i += 1;}
    }
    int len = 0;
    for(int i = 0;i < v.size() ; i++) {
        if(v[i] == 'B') {
            c[id].push_back(len + 1) ;
            len = 0;
        }
        else len++ ;
    }
    bad += len ;

    return ;
}

int calc() {
    /// vector<int> 1...n
    /// xian - hou
    /// take small
    // for(int i=1;i<=n;++i){
    //     for(auto x:c[i]){
    //         cerr<<" "<<x;
    //     }
    //     cerr<<endl;
    // }
    for(int i=1;i<=n;++i){
        while(1){
            int p=0;
            vector<int> qwq;
            int j=0;
            int ok=0;
            for(;j<(int)c[i].size()-2;++j){
                if(c[i][j+1]>c[i][j]){
                    qwq.push_back(c[i][j]+c[i][j+2]-c[i][j+1]);
                    j+=3;
                    ok=1;
                    break;
                }
                qwq.push_back(c[i][j]);
            }
            if(!ok)break;
            while(j<(int)c[i].size()){
                qwq.push_back(c[i][j++]);
            }
            c[i]=qwq;
        }
    }
    vector<int> o(n+1);
    for(int i=1;i<=n;++i){
        if(c[i].size()==2&&c[i][0]>c[i][1]){
            o[i]=1;
            continue;
        }
        reverse(c[i].begin(),c[i].end());
    }
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
    for(int i=1;i<=n;++i){
        if(o[i]||c[i].size()==0)continue;
        q.push({c[i].back(),i});
    }
    int ans=0;
    int op=0;
    while(!q.empty()){
        int u=q.top().second;
        q.pop();
        ans+=(op==0?1:-1)*c[u].back();
        op^=1;
        c[u].pop_back();
        if(c[u].size()){
            q.push({c[u].back(),u});
        }
    }
    vector<int> tmp;
    for(int i=1;i<=n;++i){
        if(o[i]){
            tmp.push_back(c[i][0]-c[i][1]);
        }
    }
    sort(tmp.begin(),tmp.end());
    for(auto x:tmp){
        ans+=(op==0?1:-1)*x;
        // op^=1;
    }
    // cerr<<" ans: "<<ans<<endl;
    return ans;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        Ins(a[i] , i);
    }
    ll ans=0;
    if(cnt % 2) ans = 1;

    int lcnt = 0;
    for(int i = 1;i <= n;i++) {
        lcnt += c[i].size() ;
    }
    if((lcnt + op) & 1) ans += bad;
    else ans -= bad ;

    if(op) ans += calc() ;
    else ans -= calc() ;

    cout << ans << '\n' ;
    return 0;
}

詳細信息

Test #1:

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

input:

5
13 29 10 1 26

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 24ms
memory: 5888kb

input:

21417
7840302172680170307 5321573529083198387 8214462622877325148 1143008495081213578 6262491513147717806 5039611704168873788 8094944116872031972 2567428672066144766 6056648091050202450 3565740003036766392 2925999037919145749 5542147304038247878 862707825558040953 4471890990246559484 263325942648568...

output:

49026

result:

wrong answer 1st numbers differ - expected: '67086', found: '49026'