Submission #342143

#TimeUsernameProblemLanguageResultExecution timeMemory
342143maskoffNice sequence (IZhO18_sequence)C++14
15 / 100
2081 ms876 KiB
#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;
}

bool solve3(vector<int> a) {
	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 = -5; i <= 5; i++) {
	 	a.pb(i);
	 	if (solve3(a)) return 1;
	 	a.pop_back();
	}
	return 0;
}


void solve() {
 	cin >> n >> m;
 	vector<int> just;
 	if (max(n, m) % min(n, m) == 0) {solve1(); return;}
 	if (min(n, m) == 2) {solve2(); return;}
 	if (max(n, m) <= 10) {solve3(just); return;}
}

int main() {   
	ios_base :: sync_with_stdio(false);               
	cin.tie(nullptr);
	srand(time(nullptr));
	int t;
	cin >> t;
	while (t--) solve();
  return 0;
}

Compilation message (stderr)

sequence.cpp: In function 'bool solve3(std::vector<int>)':
sequence.cpp:45:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   45 |  if (a.size() == max(n, m)) {
      |      ~~~~~~~~~^~~~~~~~~~~~
sequence.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    for (int i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
sequence.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     if (i + n - 1 >= a.size()) continue;
      |         ~~~~~~~~~~^~~~~~~~~~~
sequence.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |    for (int i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
sequence.cpp:55:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if (i + m - 1 >= a.size()) continue;
      |         ~~~~~~~~~~^~~~~~~~~~~
#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...