답안 #374020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374020 2021-03-06T12:41:13 Z gustason ASM (LMIO18_asm) C++11
0 / 100
1 ms 364 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') {
                if (j.second < 0) return false;
                x *= j.second;
            } else if (j.first == 'a') {
                if (j.second < 0) return false;
                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;

    int diff = b[0].second - b[0].first;
    curr.push_back({'a', diff});
    if (diff < 0) {
        curr.pop_back();
        curr.push_back({'m', 0});
        b[0].first = 0;
        diff = b[0].second - b[0].first;
        if (diff != 0) curr.push_back({'a', diff});
    }
    if (diff == 0) curr.pop_back();
    curr.push_back({'p', 0});
    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:53:9: warning: unused variable 'best' [-Wunused-variable]
   53 |     int best = 100;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -