이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
map<pii, vector<int> > mp;
vector<int> f(int n, int s) {
if(n == 1) return { s };
if(mp.count({ n, s })) return mp[{ n, s }];
vector<int> ans;
for(int i=1; i*i<=n; i++) {
if(n % i == 0 && i > 1) {
auto res = f(n/i, s+i-1);
for(int &x : res) ans.push_back(x);
}
if(n % i == 0 && i * i != n && n / i > 1) {
auto res = f(n/(n/i), s+(n/i)-1);
for(int &x : res) ans.push_back(x);
}
}
sort(ans.begin(), ans.end());
vector<int> ans2;
if(ans.size() > 0) {
ans2.push_back(ans[0]);
for(int i=1; i<ans.size(); i++) if(ans[i] != ans2.back()) ans2.push_back(ans[i]);
}
return mp[{ n, s }] = ans2;
}
signed main() {
//a b c
//(a + 1)(b + 1)(c + 1) = n
//maks log(n) razlicni
//baska (a + 1), (b + 1), (c + 1) | n
int n;
cin >> n;
vector<int> ans = f(n, 0);
cout << ans.size() << '\n';
for(int &x : ans) cout << x << " ";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
toy.cpp: In function 'std::vector<int> f(int, int)':
toy.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=1; i<ans.size(); i++) if(ans[i] != ans2.back()) ans2.push_back(ans[i]);
| ~^~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |