Submission #91940

# Submission time Handle Problem Language Result Execution time Memory
91940 2018-12-31T15:04:51 Z popovicirobert Nice sequence (IZhO18_sequence) C++14
15 / 100
9 ms 1144 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;
        }
        cout << pos << "\n";
        for(i = 1; i <= pos; i++) {
            cout << sign * arr[i] << " ";
        }
        cout << "\n";
    }
    //cin.close();
    //cout.close();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 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 380 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 380 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 3 ms 504 KB Ok
7 Correct 8 ms 1016 KB Ok
8 Correct 5 ms 632 KB Ok
9 Correct 9 ms 1144 KB Ok
10 Correct 6 ms 760 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Jury has the better answer : jans = 6, pans = 5
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 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 380 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 376 KB Ok
16 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 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 380 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 380 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 504 KB Ok
19 Correct 8 ms 1016 KB Ok
20 Correct 5 ms 632 KB Ok
21 Correct 9 ms 1144 KB Ok
22 Correct 6 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 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 380 KB Ok
11 Correct 2 ms 376 KB Ok
12 Correct 2 ms 376 KB Ok
13 Correct 2 ms 376 KB Ok
14 Correct 2 ms 376 KB Ok
15 Correct 2 ms 380 KB Ok
16 Correct 2 ms 376 KB Ok
17 Correct 2 ms 376 KB Ok
18 Correct 3 ms 504 KB Ok
19 Correct 8 ms 1016 KB Ok
20 Correct 5 ms 632 KB Ok
21 Correct 9 ms 1144 KB Ok
22 Correct 6 ms 760 KB Ok
23 Correct 2 ms 376 KB Ok
24 Correct 2 ms 376 KB Ok
25 Correct 2 ms 376 KB Ok
26 Incorrect 2 ms 376 KB Jury has the better answer : jans = 9, pans = 8
27 Halted 0 ms 0 KB -