| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 342160 | maskoff | Nice sequence (IZhO18_sequence) | C++17 | 6 ms | 876 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};
int n, m;
void solve1() {
cout << max(n, m) - 1 << endl;
for (int i = 1; i < max(n, m); i++)
cout << (min(n, m) == n ? -1 : 1) << " ";
cout << endl;
}
void solve2() {
cout << max(n, m) << endl;
cout << (n == 2 ? 1 : -1) * (max(n, m) / 2 + 1) << " ";
for (int i = 1; i <= max(n, m) / 2; i++)
if (n == 2) cout << "-1000000 999999 ";
else cout << "1000000 -999999 ";
cout << endl;
}
vector<int> a;
bool solve3() {
if (a.size() == max(n, m)) {
for (int i = 0; i < a.size(); i++) {
ll sum = 0;
if (i + n - 1 >= a.size()) continue;
int cnt = n;
for (int j = i; cnt > 0; j++, cnt--) sum += a[j];
if (sum >= 0) return 0;
}
for (int i = 0; i < a.size(); i++) {
ll sum = 0;
if (i + m - 1 >= a.size()) continue;
int cnt = m;
for (int j = i; cnt > 0; j++, cnt--) sum += a[j];
if (sum <= 0) return 0;
}
for (int to : a) cout << to << " ";
cout << endl;
return 1;
}
for (int i = -3; i <= 3; i++) {
if (i == 0) continue;
a.pb(i);
if (solve3()) return 1;
a.pop_back();
}
return 0;
}
void solve4() {
int k = min(n, m);
vector<int> ans;
for (int i = 1; i < (k + 1) / 2; i++)
ans.pb(-1e6);
if (n % 2 == 0) ans.pb(1);
else ans.pb(-1e6 + 1);
for (int i = 1; i < (k + 1) / 2; i++)
ans.pb(1e6);
vector<int> all;
int last = 0;
while (all.size() < max(n, m)) {
all.pb(ans[last]);
last++;
if (last == k) last = 0;
}
cout << max(n, m) << endl;
for (int to : all) cout << to * (n == min(n, m) ? +1 : -1) << " ";
cout << endl;
}
void solve() {
cin >> n >> m;
a.clear();
if (max(n, m) % min(n, m) == 0) {solve1(); return;}
if (min(n, m) == 2) {solve2(); return;}
solve4();
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
srand(time(nullptr));
int t;
cin >> t;
while (t--) solve();
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
