이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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});
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
asm.cpp: In function 'int main()':
asm.cpp:53:9: warning: unused variable 'best' [-Wunused-variable]
53 | int best = 100;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |