답안 #497975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497975 2021-12-24T07:30:10 Z Nalrimet Nice sequence (IZhO18_sequence) C++17
0 / 100
2000 ms 124680 KB
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
using namespace std;
 
const int N = 2 * 1e6 + 5;
const long long inf = 1000000000;
 
#define F first
#define S second
#define pb push_back
 
int n, t, a, b, lastans, k, id, m;
bool used[N];
pair<int, int> pref[N];
vector<int> top, g[N];
 
void create(int v){
    for(int i = 0; i <= v; ++i){
        g[i].clear();
        used[i] = 0;
    }
    for(int i = 0; i <= v; ++i){
        if(i + n <= v) g[i + n].pb(i);
        if(i - m >= 0) g[i - m].pb(i);
    }
}
/*
0 -> 3 -> 2 1
 
2 3 0 1
0 1 2 3
 
2 3 0 1
*/
bool check(int v){
    used[v] = 1;
    for(auto to : g[v]){
        if(used[to] == 1){
            return 1;
        }
        else if(used[to] == 0){
            if(check(to)) return 1;
        }
    }
    used[v] = 2;
    return 0;
}
 
void topsort(int v){
    used[v] = 1;
    for(auto to : g[v]){
        if(used[to] == 0){
            topsort(to);
        }
    }
    top.pb(v);
}
 
 main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin >> t;
 
    while(t--){
        cin >> n >> m;
        int l = 0, r = n + m , mid;
        while(l < r){
            cout << l << ' ' << r << '\n';
            mid = (l + r) / 2;
            create(mid);
            for(int i = 0; i <= mid; ++i){
                cout << i << '\n';
                for(auto to : g[i]){
                    cout << to << ' ';
                }
                cout << '\n';
            }
            cout << "OK\n";
            if(!check(mid)) l = mid;
            else r = mid - 1;
        }

        //l = n + m - 1 - __gcd(n, m);
        cout << l << '\n';
        create(l);
        top.clear();
        for(int i = 0; i <= l; ++i){
            if(!used[i]) topsort(i);
        }
        reverse(top.begin(), top.end());
        for(int i = 0; i < top.size(); ++i){
//            cout << top[i] << ' ' << i << '\n';
            pref[i] = {top[i], i};
        }
//        cout << '\n';
        sort(pref, pref + top.size());
        for(int i = 1; i < top.size(); i++){
            cout << (pref[i].S - pref[i - 1].S) << ' ';
        }
        cout << '\n';
    }
 
    return 0;
 
}
 
// merge sort tree
// l <= b <= r
// r < b

Compilation message

sequence.cpp:65:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 |  main() {
      |  ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:100:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |         for(int i = 0; i < top.size(); ++i){
      |                        ~~^~~~~~~~~~~~
sequence.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int i = 1; i < top.size(); i++){
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47180 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2080 ms 124680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47284 KB Jury has the better answer : jans = 2, pans = 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2087 ms 116932 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47180 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47180 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47180 KB All the numbers must be nonzero
2 Halted 0 ms 0 KB -