답안 #374013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374013 2021-03-06T12:31:38 Z gustason ASM (LMIO18_asm) C++11
0 / 100
1 ms 492 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
int n;
vector<pair<int, int>> b;
//void go(pair<int, int> a, bool print) {
//    if (print) {
//
//    }
//}
bool check(vector<pair<char, int>> ins) {
    for(int i = 0; i < n; i++) {
        int x = b[i].first;
        for(auto j : ins) {
            if (j.first == 'm') {
                x *= j.second;
            } else if (j.first == 'a') {
                x += j.second;
            }
            if (x > b[i].second) return false;
        }
        if (x != b[i].second) return false;
    }
    return true;
}
void printAns(vector<pair<char, int>> ans) {
    cout << ans.size() << "\n";
    for(auto i : ans) {
        if (i.first == 'm') {
            cout << "multiply " << i.second;
        } else if (i.first == 'a') {
            cout << "add " << i.second;
        } else {
            cout << "print";
        }
        cout << "\n";
    }
    exit(0);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    b.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> b[i].first >> b[i].second;
    }
    sort(b.begin(), b.end(), [](pair<int, int>& left, pair<int, int>& right){return left.second < right.second;});

    int best = 100;
    vector<pair<char, int>> ans;
    vector<pair<char, int>> curr;

    curr.push_back({'a', b[0].second - b[0].first});
    if (check(curr)) {
        printAns(curr);
    }

    // one step
    for(int j = 2; j <= 100; j++) {
        vector<pair<char, int>>().swap(curr);
        curr.push_back({'m', j});
        int add = b[0].second - (b[0].first * j);
        if (add > 0) {
            curr.push_back({'a', j});
        }
        if (check(curr)) {
            printAns(curr);
        }
    }

    // split
//    for(int j = )

    cout << -1;
    return 0;
}

Compilation message

asm.cpp: In function 'int main()':
asm.cpp:51:9: warning: unused variable 'best' [-Wunused-variable]
   51 |     int best = 100;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -