답안 #225428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225428 2020-04-20T14:41:43 Z emil_physmath Nice sequence (IZhO18_sequence) C++17
0 / 100
10 ms 9728 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
const int maxN = 100001;

vector<int> nei[400001];
int a[400001];
bool used[400001];

void DFS(int v, vector<int>& order)
{
    used[v] = true;
    for (int to: nei[v])
        if (!used[to])
            DFS(to, order);
    order.push_back(v);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        int len = 0;
        int i = 0;
        do {
            len = max(len, i += n);
            while (i - m >= 0) i -= m;
        } while (i);
        --len;
        for (int i = 1; i <= len; ++i)
        {
            if (i - n >= 0)
                nei[i].push_back(i - n);
            if (i - m >= 0)
                nei[i - m].push_back(i);
        }
        vector<int> order;
        for (int i = 0; i <= len; ++i)
            if (!used[i])
                DFS(i, order);
        reverse(order.begin(), order.end());
        vector<int> pref(len + 1);
        for (int i = 0; i < order.size(); ++i)
            pref[order[i]] = i;
        for (int i = 1; i < pref.size(); ++i)
            pref[i] -= pref[0];
        pref[0] = 0;
        for (int i = 1; i <= len; ++i)
            a[i] = pref[i] - pref[i - 1];
        cout << len << endl;
        for (int i = 1; i <= len; ++i)
            cout << a[i] << ' ';
        cout << '\n';
    }
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < order.size(); ++i)
                         ~~^~~~~~~~~~~~~~
sequence.cpp:57:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 1; i < pref.size(); ++i)
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 9728 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -