답안 #91938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91938 2018-12-31T15:04:10 Z popovicirobert Nice sequence (IZhO18_sequence) C++14
6 / 100
2 ms 380 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int INF = 999999999;
const int MAXN = (int) 2e5;

void dfs(int nod, vector < vector <int> > &g, vector <int> &vis, bool &ok) {
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(vis[it] == 0) {
            dfs(it, g, vis, ok);
        }
        else if(vis[it] == 1) {
            ok = 0;
        }
    }
    vis[nod] = 2;
}

inline bool check(int len, int n, int m) {
    int i;
    vector < vector <int> > g(len + 1);
    for(i = 1; i <= len; i++) {
        if(i >= n) {
            g[i - n].push_back(i);
        }
        if(i >= m) {
            g[i].push_back(i - m);
        }
    }
    vector <int> vis(len + 1);
    bool ok = 1;
    for(i = 1; i <= len; i++) {
        if(vis[i] == 0) {
            dfs(i, g, vis, ok);
        }
    }
    return ok;
}

inline int solve(int n, int m) {
    int res = 0;
    for(int step = 1 << 15; step; step >>= 1) {
        if(check(res + step, n, m)) {
            res += step;
        }
    }
    return res;
}

int arr[MAXN + 1];
ll sp[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int t, i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    while(t > 0) {
        t--;
        int n, m;
        cin >> n >> m;
        int mn = min(n, m), mx = max(n, m);
        if(mx % mn == 0) {
            cout << mx - 1 << "\n";
            int sign = 1;
            if(mn == n) {
                sign = -1;
            }
            for(i = 1; i < mx; i++) {
                cout << sign << " ";
            }
            if(mx > 1) {
                cout << "\n";
            }
            continue;
        }
        int val = INF / (mn - 1);
        int pos = 0;
        while(1) {
            for(i = 1; i < mn; i++) {
                arr[++pos] = val;
                sp[pos] = sp[pos - 1] + val;
            }
            arr[++pos] = -val * (mn - 1) - 1;
            sp[pos] = arr[pos] + sp[pos - 1];
            if(pos >= mx && sp[pos] - sp[pos - mx] <= 0) {
                pos--;
                break;
            }
        }
        int sign = 1;
        if(n != mn) {
            sign = -1;
        }
        for(i = 1; i <= pos; i++) {
            cout << sign * arr[i] << " ";
        }
        cout << "\n";
    }
    //cin.close();
    //cout.close();
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Jury has the better answer : jans = 3, pans = -999999999
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 376 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Incorrect 2 ms 376 KB All the numbers must be nonzero
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Incorrect 2 ms 376 KB Jury has the better answer : jans = 3, pans = -999999999
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
9 Correct 2 ms 376 KB Ok
10 Correct 2 ms 376 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Incorrect 2 ms 376 KB Jury has the better answer : jans = 3, pans = -999999999
14 Halted 0 ms 0 KB -