답안 #667283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667283 2022-12-01T03:41:57 Z Kalashnikov Nice sequence (IZhO18_sequence) C++17
15 / 100
9 ms 1076 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

void solve(int tc) {
	int n, m;
	cin >> n >> m;
	int coef = 1;
	if(n > m) {
		swap(n , m);
		coef *= -1;
	}
	if(m % n == 0) {
		cout << m-1 << '\n';
		for(int i = 1; i < m; i ++) {
			cout << (-1)*coef << ' ';
		}	
		cout << '\n';
		// return;c
		return;
	}
	int mx = 9e8;
	int otr = -mx/(n-1);
	int psv = -otr*(n-1)-1;
	vector<int> vec;
	int sum = 0;
	for(int i = 1; i <= m; i ++) {
		if(i%n == m%n) {
			vec.push_back(psv);
		}
		else {
			vec.push_back(otr);
		}
		sum += vec.back();
	}
	int cur = 0;
	for(int i = m+1; sum > 0; i ++) {
		if(i%n == m%n) {
			vec.push_back(psv);
		}
		else {
			vec.push_back(otr);
		}
		sum += vec.back();
		sum -= vec[cur++];
		if(sum <= 0) {
			vec.pop_back();
			break;
		}
	}	
	psv = mx/(n-1);
	otr = -psv*(n-1)-1;
	vector<int> vec1;
	sum = 0;
	for(int i = 1; i <= m; i ++) {
		if(i%n == (m-1)%n) {
			vec1.push_back(otr);
		}
		else {
			vec1.push_back(psv);
		}
		sum += vec1.back();
	}
	cur = 0;
	for(int i = m+1; sum > 0; i ++) {
		if(i%n == (m-1)%n) {
			vec1.push_back(otr);
		}
		else {
			vec1.push_back(psv);
		}
		sum += vec1.back();
		sum -= vec1[cur++];
		if(sum <= 0) {
			vec1.pop_back();
			break;
		}
	}	
	if(1) swap(vec,vec1);
	cout << vec.size() << '\n';
	for(auto to: vec) {
		cout << to*coef << ' ';
	}
	cout << '\n';
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message

sequence.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   98 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 0 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 1 ms 212 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 2 ms 340 KB Ok
7 Correct 8 ms 980 KB Ok
8 Correct 4 ms 596 KB Ok
9 Correct 9 ms 1076 KB Ok
10 Correct 6 ms 724 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Incorrect 0 ms 212 KB Jury has the better answer : jans = 9, pans = 8
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Jury has the better answer : jans = 6, pans = 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 0 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 0 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 0 ms 212 KB Ok
16 Incorrect 0 ms 212 KB Jury has the better answer : jans = 9, pans = 8
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 0 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 1 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 1 ms 212 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 2 ms 340 KB Ok
19 Correct 8 ms 980 KB Ok
20 Correct 4 ms 596 KB Ok
21 Correct 9 ms 1076 KB Ok
22 Correct 6 ms 724 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Incorrect 0 ms 212 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 0 ms 212 KB Ok
3 Correct 0 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 0 ms 212 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 0 ms 212 KB Ok
9 Correct 0 ms 212 KB Ok
10 Correct 0 ms 212 KB Ok
11 Correct 0 ms 212 KB Ok
12 Correct 0 ms 212 KB Ok
13 Correct 1 ms 212 KB Ok
14 Correct 0 ms 212 KB Ok
15 Correct 1 ms 212 KB Ok
16 Correct 1 ms 212 KB Ok
17 Correct 1 ms 212 KB Ok
18 Correct 2 ms 340 KB Ok
19 Correct 8 ms 980 KB Ok
20 Correct 4 ms 596 KB Ok
21 Correct 9 ms 1076 KB Ok
22 Correct 6 ms 724 KB Ok
23 Correct 0 ms 212 KB Ok
24 Correct 0 ms 212 KB Ok
25 Correct 0 ms 212 KB Ok
26 Incorrect 0 ms 212 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -