제출 #495807

#제출 시각아이디문제언어결과실행 시간메모리
495807ZielNice sequence (IZhO18_sequence)C++17
15 / 100
9 ms844 KiB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = true;
void setIO(const string &f = "");

void solve() {
    int n, m;
    cin >> n >> m;
    if (n == m) {
    	cout << n - 1 << '\n';
    	for (int i = 0; i < n - 1; i++)
    		cout << "1 ";
    } else if (n < m) {
    	if (n == 1) {
    		cout << m - 1 << '\n';
    		for (int i = 1; i < m; i++)
    			cout << "-1 ";
    	} else if (n == 2) {
    		cout << m - 1 + (m % 2) << '\n';
			int x = (m - 1) / 2 + 1;
			for (int i = 1; i <= m - 1 + (m % 2); i++) {
				if (i % 2 == 0)
					cout << -(x + 1) << ' ';
				else
					cout << x << ' ';
			}
    	} else if (m % n == 0) {
    		cout << m - 1 << '\n';
			int x = m / n - 1;
			for (int i = 1; i < m; i++) {
				if (i % n == 0)
					cout << -(x * (n - 1) + 1) << ' ';
				else
					cout << x << ' ';
			}
    	} else {
    		m = (m + n - 1) / n * n - 1;
    		cout << m << '\n';
			int x = (m + 1) / n - 1;
			for (int i = 1; i <= m; i++) {
				if (i % n == 0)
					cout << -(x * (n - 1) + 1) << ' ';
				else
					cout << x << ' ';
			}
    	}
    } else {
    	swap(n, m);
    	if (n == 1) {
    		cout << m - 1 << '\n';
    		for (int i = 1; i < m; i++)
    			cout << "1 ";
    	} else if (n == 2) {
    		cout << m - 1 + (m % 2) << '\n';
			int x = (m - 1) / 2 + 1;
			for (int i = 1; i <= m - 1 + (m % 2); i++) {
				if (i % 2 == 0)
					cout << (x + 1) << ' ';
				else
					cout << -x << ' ';
			}
    	} else if (m % n == 0) {
    		cout << m - 1 << '\n';
			int x = m / n - 1;
			for (int i = 1; i < m; i++) {
				if (i % n == 0)
					cout << (x * (n - 1) + 1) << ' ';
				else
					cout << -x << ' ';
			}
    	}  else {
    		m = (m + n - 1) / n * n - 1;
    		cout << m << '\n';
			int x = (m + 1) / n - 1;
			for (int i = 1; i <= m; i++) {
				if (i % n == 0)
					cout << (x * (n - 1) + 1) << ' ';
				else
					cout << -x << ' ';
			}
    	}
    }
    cout << '\n';
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'void setIO(const string&)':
sequence.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...