結果

問題 No.3278 Avoid Division
ユーザー GOTKAKO
提出日時 2025-09-20 02:30:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 202,984 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-20 02:31:00
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    auto A = [&](int pos) -> string {
        string ret = "A[";
        ret += to_string(pos+1);
        ret += "]";
        return ret;
    };
    auto C = [&](int c) -> string {
        if(c >= 1) return A(c-1);
        else return string(1,-c+'a');
    };
    auto f = [&](string s,int a,int b,int c) -> string {
        string ret = s;
        ret += " "+C(a);
        ret += " "+C(b);
        ret += " "+C(c);
        return ret;
    };

    int N; cin >> N;
    bool div = false;
    vector<string> ope;
    for(int i=0; i<N; i++){    
        char c; int a; cin >> c >> a;
        if(c == '+'){
            if(div) ope.push_back(f("mul",-1,i+1,-2)),ope.push_back(f("add",-0,-0,-1));
            else ope.push_back(f("add",0,i+1,0));
        }
        else if(c == '*') ope.push_back(f("mul",0,0,i+1));
        else{
            if(div) ope.push_back(f("mul",-2,-2,i+1));
            else ope.push_back(f("add",-2,-2,i+1));
            div = true;
        }
    }
    if(div) ope.push_back(f("div",0,0,-2));
    cout << ope.size() << "\n";
    for(auto &s : ope) cout << s << "\n";
}

 
0