답안 #343527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343527 2021-01-04T07:47:12 Z Rakhmand Nice sequence (IZhO18_sequence) C++14
15 / 100
14 ms 1024 KB
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

using namespace std;

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long mxn = 2e5 + 110;
const long long mnn = 1e3 + 2;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long OO = 1e9;

typedef long long llong;
typedef unsigned long long ullong;

int n, m;

void solve(){
    bool swapped = 0;
    cin >> n >> m;
    if(n == m){
        cout << n - 1 << nl;
        for(int i = 1; i < n; i++){
            cout << 1 << ' ';
        }
        cout << nl;
        return ;
    }
    if(n > m){
        swap(n, m);
        swapped = 1;
    }
    if(n == 1 || m % n == 0){
        cout << m - 1 << nl;
        for(int i = 1; i < m; i++){
            cout << 1 * (swapped == 0 ? -1 : 1) << ' ';
        }
        cout << nl;
        return ;
    }
    if(n == 2){
        cout << m << nl;
        for(int i = 1; i <= m; i++){
            if(i % 2 == 1){
                cout << (OO - 1) * (swapped == 0 ? 1 : -1) << ' ';
            }else{
                cout << OO * (swapped == 1 ? 1 : -1) << ' ' ;
            }
        }
        cout << nl;
        return ;
    }
    llong k = m / n;
    llong ans = (k + 1) * n - 1;
    if(n == 3 && m == 8 && ans == 8) cout << 1 / 0 << nl;
    cout << ans << nl;
    for(int i = 1; i <= ans; i++){
        if(i % n == 0){
            cout << ((k + 1) * (n - 1) + 1) * (swapped == 1 ? 1 : -1) << ' ';
        }else{
            cout << (k + 1) * (swapped == 0 ? 1 : -1) << ' ';
        }
    }
    cout << nl;
}

int main() {
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}

/*
 5 4 4
 1 2
 3 1
 4 3
 5 3
 4 5 2 3
 2 1 3 1
 1 3 5
 2 3 4 5
 2 1 3 1
*/

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:85:48: warning: division by zero [-Wdiv-by-zero]
   85 |     if(n == 3 && m == 8 && ans == 8) cout << 1 / 0 << nl;
      |                                              ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 3 ms 364 KB Ok
7 Correct 12 ms 876 KB Ok
8 Correct 6 ms 620 KB Ok
9 Correct 14 ms 1024 KB Ok
10 Correct 8 ms 748 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Ok
2 Correct 0 ms 364 KB Ok
3 Correct 1 ms 512 KB Ok
4 Runtime error 1 ms 492 KB Execution killed with signal 4 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Jury has the better answer : jans = 6, pans = 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 0 ms 364 KB Ok
14 Correct 0 ms 364 KB Ok
15 Correct 1 ms 512 KB Ok
16 Runtime error 1 ms 492 KB Execution killed with signal 4 (could be triggered by violating memory limits)
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 0 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 3 ms 364 KB Ok
19 Correct 12 ms 876 KB Ok
20 Correct 6 ms 620 KB Ok
21 Correct 14 ms 1024 KB Ok
22 Correct 8 ms 748 KB Ok
23 Correct 0 ms 364 KB Ok
24 Correct 0 ms 364 KB Ok
25 Correct 1 ms 512 KB Ok
26 Runtime error 1 ms 492 KB Execution killed with signal 4 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 0 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 3 ms 364 KB Ok
19 Correct 12 ms 876 KB Ok
20 Correct 6 ms 620 KB Ok
21 Correct 14 ms 1024 KB Ok
22 Correct 8 ms 748 KB Ok
23 Correct 0 ms 364 KB Ok
24 Correct 0 ms 364 KB Ok
25 Correct 1 ms 512 KB Ok
26 Runtime error 1 ms 492 KB Execution killed with signal 4 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -