結果

問題 No.1404 誕生日プレゼント
ユーザー pockynypockyny
提出日時 2022-01-31 05:48:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,132 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 5,212 KB
最終ジャッジ日時 2023-09-02 02:00:25
合計ジャッジ時間 26,324 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 44 ms
4,912 KB
testcase_24 AC 44 ms
4,932 KB
testcase_25 RE -
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
ll a[100010],b[100010],d[100010],p = 223577;
ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= p;
        (a *= a) %= p; x /= 2;
    }
    return ret;
}

vector<pair<int,int>> ans;
void solve(int i,int j){
    ans.push_back({i,j});
    (a[i] += a[j]) %= p;
}

void fin(){
    for(int i=0;i<ans.size();i++){
        cout << 1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    cout << 2 << endl;
}

int main(){
    int i,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=0;i<n;i++) cin >> b[i];
    bool f1 = false,f2 = false;
    for(i=0;i<n;i++){
        if(a[i]) f1 = true;
        if(b[i]) f2 = true;
    }
    if(!(f1^f2)){
        cout << -1 << endl;
        return 0;
    }
    cout << "Yes\n";
    if(!f1 && !f2){
        cout << 0 << endl;
        return 0;
    }
    vector<int> z1,z2;
    int j = -1,k = 0;
    for(i=0;i<n;i++){
        if(a[i]) z1.push_back(i);
        if(b[i]) z2.push_back(i);
    }
    if(z1.size()==1 && z2.size()==1 && z1[0]==z2[0]){
        j = z1[0];
        for(i=0;i<p;i++){
            if(a[j]!=b[j]) solve(j,j);
        }
        if(a[j]==b[j]) fin();
        else cout << -1 << endl;
        return 0;
    }
    j = z1[0],k = z2[0];
    if(j==k){
        if(z1.size()>1) j = z1[1];
        else k = z2[1];
    } 
    ll inv = pw(a[j],p - 2);
    for(i=0;i<n;i++){
        (a[i] *= inv) %= p; (b[i] *= inv) %= p;
    }
    if(a[k]>b[k]) a[k] -= p;
    ll dif = b[k] - a[k];
    while(dif){
        if(dif&1) solve(k,j);
        solve(j,j); dif /= 2;
    }
    ll inv2 = pw(a[k],p - 2);
    for(i=0;i<n;i++){
        (a[i] *= inv2) %= p;
        (b[i] *= inv2) %= p;
        d[i] = b[i] - a[i];
        if(d[i]<0) d[i] += p;
    }
    for(j=0;j<20;j++){
        bool f = true;
        for(i=0;i<n;i++){
            if(d[i]) f = false;
            if(d[i]&1){
                solve(i,k); d[i] /= 2;
            }
        }
        if(f) break;
        solve(k,k);
    }
    for(i=0;i<p;i++){
        if(a[k]==b[k]) continue;
        solve(k,k);
    }
    fin();
}
0