# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107170 | Shafin666 | Nice sequence (IZhO18_sequence) | C++14 | 11 ms | 896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define read_input freopen("in.txt","r", stdin)
#define print_output freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
int a[200005];
int main()
{
//read_input;
//print_output;
int tc, p = 2e5+10;
cin >> tc;
while(tc--) {
int n, m; int mul = 1;
cin >> n >> m;
if(m < n) mul *= -1, swap(n, m);
int delta = m-n;
if(delta*2 >= m || n == 1 || m == 1 || n == m) {
if(n == 1 && m == 1) {cout << 0 << endl; continue;}
if(m % n != 0) {
cout << m << endl;
int k = (m + n - 1)/n;
/*int y = 2e5+10;
int x = floor((ld)y * ((ld)m/(ld)k - 1.0)) + 1;
y = y * -1;*/
int x, y;
while(1) {
y = rand() % 1000008 + 501;
x = floor((ld)y * ((ld)m/(ld)k - 1.0)) + 1;
if(abs(x*k - y*(m-k)) == 0) continue;
else break;
//if(x < (n-1)*y) break;
}
y = y * -1;
//cout << x << " " << y << endl;
for(int i = 0; i < m; i++) {
if(i % n == 0) cout << x*mul << " ";
else cout << y*mul << " ";
} cout << endl;
continue;
}
cout << m-1 << endl;
for(int i = 1; i < m; i++) cout << -1*mul << " "; cout << endl;
continue;
}
cout << m << endl;
for(int i = 1; i <= delta; i++) a[i] = p * mul;
for(int i = m; i > m-delta; i--) a[i] = p * mul;
int total = delta * p * 2 - 1, left = m - 2*delta;
for(int i = delta+1; i < m-delta; i++) a[i] = total/left * -1 * mul;
a[m-delta] = -1 * (total - (total/left)*(left-1)) * mul;
for(int i = 1; i <= m; i++) cout << a[i] << " "; cout <<endl;
}
return 0;
}
Compilation message (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... |