Submission #145003

# Submission time Handle Problem Language Result Execution time Memory
145003 2019-08-18T11:17:30 Z osaaateiasavtnl Library (JOI18_library) C++14
19 / 100
751 ms 640 KB
#include <bits/stdc++.h>
using namespace std; 
mt19937 rnd(228);
vector <int> ans, pos;
int N;
#ifdef HOME
int Q = 0;
int Query(vector <int> m) { 
    if (m.size() == 1) return 1;
    ++Q;
    vector <bool> used(N);
    for (int i = 0; i < N; ++i) {
        if (m[i]) used[pos[i]] = 1;
    }   
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += used[i] && (!i || !used[i - 1]);
    }   
    return ans;
}
void Answer(vector <int> a) { 
    cout << "Q = " << Q << '\n';
    auto b = a; reverse(b.begin(), b.end());
    if (a == ans || b == ans) cout << "correct\n";
    else {
        for (int e : ans) cout << e << ' '; cout << '\n';
        for (int e : a) cout << e << ' '; cout << '\n';
        cout << "WA\n";
        exit(0);
    }
}
#else
#include "library.h"
#endif

#define ii pair <int, int>
#define app push_back
// Query()
// Answer()
vector <ii> ed;
vector <int> g[1001];
int query(vector<int> v) {
    vector<int> m(N,0);
    for(int i:v) m[i]=1;
    return Query(m);
}
int new_edge(vector <int> v) {
    int ans = v.size() - query(v);
    vector<int> m(N,0);
    for(int i:v) m[i]=1;    
    for (auto e : ed) ans -= m[e.first] && m[e.second];
    return ans; 
}
void Solve(int n) {
    #ifdef HOME
    Q = 0;
    #endif
    N = n;
    for (int i = 0; i < 1001; ++i) g[i].clear();
    ed.clear();
    for (int t = 0; t < n - 1; ++t) {
        vector <int> cur;
        for (int i = 0; i < n; ++i) cur.app(i);
        while (cur.size() > 2) {
            int m = (cur.size() + 1) >> 1;
            while (1) {
                shuffle(cur.begin(), cur.end(), rnd);
                vector <int> l, r;
                for (int i = 0; i < m; ++i) l.app(cur[i]);
                for (int i = m; i < cur.size(); ++i) r.app(cur[i]);
                if (new_edge(l)) {
                    cur = l;
                    break;
                }
                if (new_edge(r)) {
                    cur = r;
                    break;
                }
            }   
        }
        ed.app({cur[0], cur[1]});
        g[cur[0]].app(cur[1]); g[cur[1]].app(cur[0]);
    }    
    vector <int> ans;
    for (int i = 0; i < n; ++i) {
        if (g[i].size() != 2) {
            ans.app(i); break;
        }
    }       
    int p = -1;
    for (int i = 0; i < n - 1; ++i) {
        for (int v : g[ans.back()]) {
            if (v != p) {
                p = ans.back();
                ans.app(v);
                break;
            }
        }
    }
    for (auto &e : ans) ++e;
    Answer(ans);
}
#ifdef HOME 
int main() {
    int t = 10;
    while (t--) {
        int N = 1000;
        ans.clear();
        pos.resize(N);
        for (int i = 1; i <= N; ++i) ans.app(i);
        shuffle(ans.begin(), ans.end(), rnd);
        for (int i = 0; i < N; ++i) pos[ans[i] - 1] = i;
        Solve(N);
    }
}
#endif

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:70:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int i = m; i < cur.size(); ++i) r.app(cur[i]);
                                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 81 ms 248 KB # of queries: 3836
2 Correct 76 ms 248 KB # of queries: 3815
3 Correct 67 ms 376 KB # of queries: 3970
4 Correct 67 ms 356 KB # of queries: 3924
5 Correct 67 ms 376 KB # of queries: 3902
6 Correct 89 ms 476 KB # of queries: 3938
7 Correct 81 ms 352 KB # of queries: 3993
8 Correct 88 ms 248 KB # of queries: 3664
9 Correct 81 ms 440 KB # of queries: 3963
10 Correct 47 ms 292 KB # of queries: 2297
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 248 KB # of queries: 0
13 Correct 2 ms 248 KB # of queries: 4
14 Correct 2 ms 376 KB # of queries: 11
15 Correct 4 ms 248 KB # of queries: 135
16 Correct 5 ms 348 KB # of queries: 296
# Verdict Execution time Memory Grader output
1 Correct 81 ms 248 KB # of queries: 3836
2 Correct 76 ms 248 KB # of queries: 3815
3 Correct 67 ms 376 KB # of queries: 3970
4 Correct 67 ms 356 KB # of queries: 3924
5 Correct 67 ms 376 KB # of queries: 3902
6 Correct 89 ms 476 KB # of queries: 3938
7 Correct 81 ms 352 KB # of queries: 3993
8 Correct 88 ms 248 KB # of queries: 3664
9 Correct 81 ms 440 KB # of queries: 3963
10 Correct 47 ms 292 KB # of queries: 2297
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 248 KB # of queries: 0
13 Correct 2 ms 248 KB # of queries: 4
14 Correct 2 ms 376 KB # of queries: 11
15 Correct 4 ms 248 KB # of queries: 135
16 Correct 5 ms 348 KB # of queries: 296
17 Incorrect 717 ms 516 KB Wrong Answer [3
18 Incorrect 698 ms 624 KB Wrong Answer [3
19 Incorrect 693 ms 376 KB Wrong Answer [3
20 Incorrect 706 ms 384 KB Wrong Answer [3
21 Incorrect 648 ms 492 KB Wrong Answer [3
22 Incorrect 749 ms 504 KB Wrong Answer [3
23 Incorrect 746 ms 364 KB Wrong Answer [3
24 Correct 299 ms 492 KB # of queries: 11153
25 Incorrect 731 ms 632 KB Wrong Answer [3
26 Incorrect 687 ms 512 KB Wrong Answer [3
27 Correct 286 ms 492 KB # of queries: 11331
28 Incorrect 728 ms 640 KB Wrong Answer [3
29 Incorrect 751 ms 372 KB Wrong Answer [3
30 Incorrect 724 ms 632 KB Wrong Answer [3