# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
507133 | Mazaalai | Nice sequence (IZhO18_sequence) | C++17 | 3 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m, mul = -11;
const int N = 2e5 + 5;
int arr[2*N];
bool vis[2*N];
void go() {
mul = -1;
cin >> n >> m;
for (int i = 0; i <= m*2; i++) {
vis[i] = 0;
arr[i] = 0;
}
if (m < n) {
swap(n, m);
mul = 1;
}
if (m % n == 0) {
cout << m-1 << '\n';
for (int i = 1; i < m; i++)
cout << 1 * mul << " \n"[i==m-1];
return;
}
if (n == 2) {
cout << m << '\n';
for (int i = 1; i <= m; i++)
cout << (i & 1 ? -m : m+1) * mul << " \n"[i==m];
return;
}
int i = 0, j = (m)%n, smol = (m-1)%n;
vector <int> pos;
while(1) {
if (!vis[i]) {
vis[i] = 1;
pos.pb(i);
i = (i + 1) % n;
}
if (!vis[j]) {
vis[j] = 1;
pos.pb(j);
j = (j + 1) % n;
}
if (i == n-1) break;
}
int lst = 0;
for (i = 0; i < n; i++)
if (pos[i] <= smol) lst = i;
int Y = pos[lst]; // 0->x, 1->y
Y = (Y+1)%n;
int a, b, c = m / n + 1, d, x, y;
a = n-1, b = 1;
d = c+1, c = m - d;
x = 10 * d;
y = 10 * a * d - 1;
lst = 1;
while(1) {
int curNum = (lst%n == Y) ? -y : x;
// cout << lst << ' ' << curNum << '\n';
arr[lst] = arr[lst-1] + curNum;
if (lst >= n) {
int tmp = arr[lst] - (lst-n >= 0 ? arr[lst-n] : 0);
if (tmp <= 0) {
// cout << tmp << ' ';
// cout << "ERR: n\n";
break;
}
}
if (lst >= m) {
int tmp = arr[lst] - (lst-m >= 0 ? arr[lst-m] : 0);
if (tmp >= 0) {
// cout << tmp << ' ';
// cout << "ERR: m\n";
break;
}
}
lst++;
// pos.pb(curNum);
// cout << curNum << ' ';
}
cout << lst-1 << '\n';
for (int i = 1; i < lst; i++) cout << arr[i]-arr[i-1] << " \n"[i==lst-1];
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int T;
cin >> T;
while(T--) go();
}
컴파일 시 표준 에러 (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... |