이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void Merge(vector<int> &big, vector<int> small)
{
vector<int> ans;
int idx = 0, jdx = 0;
for (; idx < big.size() || jdx < small.size();)
{
if (idx >= big.size())
ans.emplace_back(small[jdx++]);
else if (jdx >= small.size())
ans.emplace_back(big[idx++]);
else if (small[jdx] < big[idx])
ans.emplace_back(small[jdx++]);
else
ans.emplace_back(big[idx++]);
}
ans.swap(big);
}
vector<int> solve(int N, int K)
{
vector<int> ans;
if (N <= K)
ans = {N - 1};
for (int i = 2; i <= sqrt(N); i++)
if (N % i == 0)
{
vector<int> v, w;
if (N / i <= K)
{
v = solve(i, N / i);
for (int &j : v)
j += (N / i - 1);
Merge(ans, v);
ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
}
if (i <= K)
{
w = solve(N / i, i);
for (int &j : w)
j += (i - 1);
Merge(ans, w);
ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
}
}
return ans;
}
signed main()
{
int N;
cin >> N;
vector<int> ans = solve(N, N);
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " \n"[i == ans.size() - 1];
}
컴파일 시 표준 에러 (stderr) 메시지
toy.cpp: In function 'void Merge(std::vector<int>&, std::vector<int>)':
toy.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (; idx < big.size() || jdx < small.size();)
| ~~~~^~~~~~~~~~~~
toy.cpp:9:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (; idx < big.size() || jdx < small.size();)
| ~~~~^~~~~~~~~~~~~~
toy.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | if (idx >= big.size())
| ~~~~^~~~~~~~~~~~~
toy.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | else if (jdx >= small.size())
| ~~~~^~~~~~~~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
toy.cpp:62:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | cout << ans[i] << " \n"[i == ans.size() - 1];
| ~~^~~~~~~~~~~~~~~~~
# | 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... |