답안 #495859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495859 2021-12-20T06:31:37 Z vinnipuh01 Nice sequence (IZhO18_sequence) C++17
15 / 100
8 ms 716 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 + 3 ) {
		cout << mx + 2 << "\n";
		for ( auto i : v ) {
			cout << i << " ";
		}
		exit(0);
	}
	for ( auto i : vv ) {
		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);
	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 if ( min( n, m ) == 2 ) {
			cout << max( n, m ) << "\n";
			mx = max( n, m );
			if ( n == 2 ) {
				for ( int i = 1; i <= mx; i ++ ) {
					if ( i % 2 )
						cout << mx << " ";
					else
						cout << ( mx * -1 ) - 1 << " ";
				}
				cout << "\n";
			}
			else {
				for ( int i = 1; i <= mx; i ++ ) {
					if ( i % 2 == 0 )
						cout << mx + 1 << " ";
					else
						cout << ( mx * -1 ) << " ";
				}
				cout << "\n";
			}
		}
		else {
			vv.push_back( n );
			vv.push_back( -n );
			vv.push_back( -m );
			vv.push_back( m );
			cout << m << "\n";
			continue;
			f(  );
		}
	}
}

/*
3 4

3 5 -9 2 
2 2 -5 2 2


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

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

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



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 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 0 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 0 ms 204 KB Ok
5 Correct 0 ms 204 KB Ok
6 Correct 3 ms 332 KB Ok
7 Correct 7 ms 620 KB Ok
8 Correct 3 ms 460 KB Ok
9 Correct 8 ms 716 KB Ok
10 Correct 5 ms 528 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 0 ms 204 KB Ok
3 Correct 0 ms 204 KB Ok
4 Incorrect 1 ms 204 KB Jury has the better answer : jans = 9, pans = 8
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Jury has the better answer : jans = 5, pans = 3
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 0 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 0 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 0 ms 204 KB Ok
16 Incorrect 1 ms 204 KB Jury has the better answer : jans = 9, pans = 8
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 0 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 1 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 1 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 0 ms 204 KB Ok
18 Correct 3 ms 332 KB Ok
19 Correct 7 ms 620 KB Ok
20 Correct 3 ms 460 KB Ok
21 Correct 8 ms 716 KB Ok
22 Correct 5 ms 528 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Incorrect 1 ms 204 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Ok
2 Correct 1 ms 204 KB Ok
3 Correct 1 ms 204 KB Ok
4 Correct 1 ms 204 KB Ok
5 Correct 1 ms 204 KB Ok
6 Correct 0 ms 204 KB Ok
7 Correct 0 ms 204 KB Ok
8 Correct 1 ms 204 KB Ok
9 Correct 1 ms 204 KB Ok
10 Correct 0 ms 204 KB Ok
11 Correct 1 ms 204 KB Ok
12 Correct 1 ms 204 KB Ok
13 Correct 1 ms 204 KB Ok
14 Correct 0 ms 204 KB Ok
15 Correct 1 ms 204 KB Ok
16 Correct 0 ms 204 KB Ok
17 Correct 0 ms 204 KB Ok
18 Correct 3 ms 332 KB Ok
19 Correct 7 ms 620 KB Ok
20 Correct 3 ms 460 KB Ok
21 Correct 8 ms 716 KB Ok
22 Correct 5 ms 528 KB Ok
23 Correct 0 ms 204 KB Ok
24 Correct 0 ms 204 KB Ok
25 Correct 0 ms 204 KB Ok
26 Incorrect 1 ms 204 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -