답안 #495942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495942 2021-12-20T08:21:42 Z vinnipuh01 Nice sequence (IZhO18_sequence) C++17
6 / 100
1 ms 204 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>

using namespace std;

const long long oo = 1000000000000000000;

long long int  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    freopen ( "sum.in", "r", stdin )
*/

vector <int> v, vv;
int a[ 200001 ], n, m;

bool ok1( int x ) {
	if ( v.size() < n - 1 )
		return true;
	int sum = 0;
	for ( int i = v.size() - 1; i >= v.size() - ( n - 1 ); i -- ) {
		sum += v[ i ];
		if ( i == v.size() - ( n - 1 ) )
			break;
	}
	sum += x;
	if ( sum < 0 )
		return true;
	return false;
}


bool ok2( int x ) {
	if ( v.size() < m - 1 )
		return true;
	int sum = 0;
	for ( int i = v.size() - 1; i >= v.size() - ( m - 1 ); i -- ) {
		sum += v[ i ];
		if ( i == v.size() - ( m - 1 ) )
			break;
	}
	sum += x;
	if ( sum > 0 )
		return true;
	return false;
}

void f( int o = 1 ) {
	if ( o == mx + 2 ) {
		for ( auto i : v ) {
			cout << i << " ";
		}
		cout << "\n";
		return;
	}
	for ( int i = -mx; i <= mx; i ++ ) {
		if ( ok1( i ) && ok2( i ) ) {
			v.push_back( i );
			f(o + 1);
			v.pop_back();
		}
	}
}

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen( "input.txt", "w", stdout );
	int t;
	cin >> t;
	while ( t -- ) {
		cin >> n >> m;
		mn = min( n, m );
		mx = max( n, m );
		if ( n % m == 0 || m % n == 0 ) {
			if ( n > m ) {
				cout << n - 1 << "\n";
				for ( int i = 1; i < n; i ++ )
					cout << 1 << " ";
			}
			else {
				cout << m - 1 << "\n";
				for ( int i = 1; i < m; i ++ )
					cout << -1 << " ";
			}
			cout << "\n";
		}
		else {
				cout << mx + 1 << "\n";
				if ( ( mx + 1 ) % mn ) {
					if ( n < m ) {
						for ( int i = 1; i <= mx + 1; i ++ ) {
							if ( i % mn ) {
								cout << mn << " ";
							}
							else
								cout << -( mn * ( mn - 1 ) + 1 ) << " ";
						}
					}
					else {
						for ( int i = 1; i <= mx + 1; i ++ ) {
							if ( i % mn ) {
								cout << -mn << " ";
							}
							else
								cout << ( mn * ( mn - 1 ) + 1 ) << " ";
						}
						
					}
				}
				else {
					if ( n < m ) {
						num = ( ( mn + 1 ) * ( mn - 1 ) );
						sum = num + 1;
						for ( int i = 1; i <= mx + 1; i ++ ) {
							if ( i % mn == 2 )
								cout << num << " ";
							else {
								if ( i % mn == 1 )
									cout << -sum / ( mn - 1 ) - 1 << " ";
								else
									cout << -sum / ( mn - 1 ) << " ";
							}
						}
					}
					else {
						num = ( ( mn + 1 ) * ( mn - 1 ) );
						sum = num + 1;
						for ( int i = 1; i <= mx + 1; i ++ ) {
							if ( i % mn == 2 )
								cout << -num << " ";
							else {
								if ( i % mn == 1 )
									cout << sum / ( mn - 1 ) + 1 << " ";
								else
									cout << sum / ( mn - 1 ) << " ";
							}
						}
					}
				}
			}
	}
}

/*
3 4

3 5 -9 2 
2 2 -5 2 2

3 5
-3 5 -3 -3 5 -3

3 7
3 3 -7 3 3 -7 3 3

3 8
-7 5 1 -7 -7  -7

3 7
4 4 -9 4 4 -9 4 4
-5 8 -4 -5 8 -4 -5 8 -4

4 11
-5 12 -4 -4 -5 12 -4 -4 -5 12 -4

3 8
-4 6 -3 -4 6 -3 -4 6 -3

4 7
-7 2 7 -7 -7 6 7 -7
-7 7 4 -7 -7 7 4 -7
4 4 4 -13 4 4 4 -13
4 -13 4 4 4 -13 4 4
4 4 4 -6 -7
-13 2 13

5 7
-5 7 -5 -7 -3 7 7 -5
7 7 -1 -7 -7 7 7 -1

3 8
-5 8 -4 -5 8 -4 -5 8 -4
3 -7 3 -7 3 -7 3 -7 3
3 11
3 3 -7 3 3 -7 3 3 -7 3 3 -7




3 8
-2 3 -2 -2 3 -2 -2 3 -2



3 5
-3 5 -3 -3 5 -3

0 0 0 0 0 0
*/

Compilation message

sequence.cpp: In function 'bool ok1(int)':
sequence.cpp:47:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |  if ( v.size() < n - 1 )
      |       ~~~~~~~~~^~~~~~~
sequence.cpp:50:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for ( int i = v.size() - 1; i >= v.size() - ( n - 1 ); i -- ) {
      |                              ~~^~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:52:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   if ( i == v.size() - ( n - 1 ) )
      |        ~~^~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp: In function 'bool ok2(int)':
sequence.cpp:63:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |  if ( v.size() < m - 1 )
      |       ~~~~~~~~~^~~~~~~
sequence.cpp:66:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for ( int i = v.size() - 1; i >= v.size() - ( m - 1 ); i -- ) {
      |                              ~~^~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:68:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   if ( i == v.size() - ( m - 1 ) )
      |        ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Incorrect 1 ms 204 KB there is incorrect sequence
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Incorrect 0 ms 204 KB there is incorrect sequence
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 1 ms 204 KB Ok
8 Correct 0 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 0 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Incorrect 0 ms 204 KB there is incorrect sequence
14 Halted 0 ms 0 KB -