結果

問題 No.2881 Mod 2^N
ユーザー HIcoder
提出日時 2024-09-10 21:55:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 119,844 KB
最終ジャッジ日時 2025-02-24 06:34:25
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,int> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;

string f(ll x){
    string res="";
    while(x>0){
        res+=to_string(x%2);
        x/=2;
    }
    reverse(res.begin(),res.end());
    return res;
}

int main(){
    ll N,X,Y;
    cin>>N>>X>>Y;

    string S=f(X);
    string T=f(Y);
    while(S.size()<T.size()){
        S="0"+S;
    }
    string tmpT=T;
    while(tmpT.size()<S.size()){
        tmpT="0"+tmpT;
       
    }

    if(S==tmpT){
        cout<<0<<endl;
        return 0;
    }
    // cout<<"S="<<S<<endl;
    // cout<<"T="<<T<<endl;

    if(S!=tmpT && tmpT.back()=='0'){
        //操作不可能
        cout<<-1<<endl;
        return 0;
    }
    // cout<<"S="<<S<<endl;
    // cout<<"T="<<T<<endl;

    vector<ll> ans;
    ans.push_back(N);

    if(T=="1"){
        cout<<1<<endl;
        cout<<N<<endl;
        return 0;
    }

    int idx=0;
    int l=0;
    int pre=0;
    while(idx<T.size()){
        if(T[idx]=='0'){
            l++;
            pre=0;
        }else{
            //T[idx]=='1'
            // cout<<"l="<<l<<endl;
            ans.push_back(l+1);
            l=0;
            pre=1;
        }
        // cout<<"idx="<<idx<<endl;

        idx++;
    }

    
    cout<<ans.size()<<endl;
    for(int v:ans){
        cout<<v<<' ';
    }
    cout<<endl;

    return 0;

    
    
}
0