제출 #495940

#제출 시각아이디문제언어결과실행 시간메모리
495940vinnipuh01Nice sequence (IZhO18_sequence)C++17
15 / 100
9 ms716 KiB
#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 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 { if ( ( mx + 1 ) / 2 < mn ) { cout << mx + 1 << "\n"; if ( ( mx + 1 ) % 2 ) { if ( n < m ) { m = mx + 1; for ( int i = 1; i <= m / 2; i ++ ) { cout << 1 << " "; } cout << -( mx - 1 ) << " "; for ( int i = 1; i <= m / 2; i ++ ) cout << 1 << " "; } else { n = mx + 1; for ( int i = 1; i <= n / 2; i ++ ) { cout << -1 << " "; } cout << ( mx - 1 ) << " "; for ( int i = 1; i <= n / 2; i ++ ) cout << -1 << " "; } cout << "\n"; } else { if ( n < m ) { m = mx + 1; for ( int i = 1; i <= m / 2; i ++ ) { cout << 1 << " "; } cout << -( mx - 1 ) << " "; for ( int i = 2; i <= m / 2; i ++ ) cout << 1 << " "; } else { n = mx + 1; for ( int i = 1; i <= n / 2; i ++ ) { cout << -1 << " "; } cout << ( mx - 1 ) << " "; for ( int i = 2; i <= n / 2; 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 */

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

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 ) )
      |        ~~^~~~~~~~~~~~~~~~~~~~~~~
#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...