답안 #64239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64239 2018-08-03T14:40:20 Z reality Amusement Park (JOI17_amusement_park) C++17
18 / 100
1455 ms 299048 KB
#include "Joi.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e4 + 5;

const int C = 60;

static vi g[N];

static set < int > G[N];

static int color[N];

static int f[N];

static int deg[N];

static int get(int k) {
    return k == f[k] ? k : f[k] = get(f[k]);
}

static int n;

static void connect(set < int > st) {
    int cnt = 0;
    for (auto u : st)
        for (auto v : st)
            if (u < v && G[u].count(v))
                ++cnt;
    assert(cnt + 1 == st.size());
}

static void dfs(int node,int prev,set < int > nodes,set < pii > degs) {
    set < int > col;
    for (auto it : nodes)
        col.insert(color[it]);
    assert(!col.count(-1));
    assert(col.size() == C);
    connect(nodes);
    for (auto it : g[node])
        if (it != prev) {
            if (nodes.count(it))
                dfs(it,node,nodes,degs);
            else {
                set < int > new_nodes;
                set < pii > new_degs;
                for (auto w : nodes)
                    new_nodes.insert(w);
                int u,v;
                auto low = degs.begin();
                if (low->se == node) 
                    ++low;
                assert(low->fi == 1);
                u = low->se;
                for (auto w : nodes)
                    if (G[u].count(w)) {
                        v = w;
                        break;
                    }
                assert(G[u].count(v));
                new_nodes.erase(u);
                new_nodes.insert(it);
                color[it] = color[u];
                --deg[u];
                --deg[v];
                ++deg[node];
                ++deg[it];
                for (auto it : new_nodes)
                    new_degs.insert(mp(deg[it],it));
                dfs(it,node,new_nodes,new_degs);
                ++deg[u];
                ++deg[v];
                --deg[node];
                --deg[it];
            }
        }
}

void Joi(int N, int M, int A[], int B[], long long X, int T) {
    n = N;
    for (int i = 0;i < n;++i)
  		f[i] = i,color[i] = -1;
  	for (int i = 0;i < M;++i) {
  		if (get(A[i]) == get(B[i]))
  			continue;
  		g[A[i]].pb(B[i]);
  		g[B[i]].pb(A[i]);
  	    G[A[i]].insert(B[i]);
        G[B[i]].insert(A[i]);
    	f[get(A[i])] = get(B[i]);
  	}
    set < int > nodes;
    set < pii > degs;
    queue < int > Q;
    int TT = -1;
    Q.push(0);
    while (!Q.empty()) {
        int node = Q.front();
        Q.pop();
        nodes.insert(node);
        color[node] = ++TT;
        if (nodes.size() == C)
            break;
        for (auto it : g[node])
            if (!nodes.count(it)) {
                Q.push(it);
            }
    }
    for (auto u : nodes)
        for (auto v : g[u])
            if (nodes.count(v) && u < v)
                ++deg[u],++deg[v];
    for (auto it : nodes)
        degs.insert(mp(deg[it],it));
    dfs(0,-1,nodes,degs);
    for (int i = 0;i < n;++i)
        MessageBoard(i,(X >> color[i]) & 1);
}
#include "Ioi.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e4 + 5;

const int C = 60;

static vi g[N];

static set < int > G[N];

static int color[N];

static int f[N];

static int deg[N];

static int get(int k) {
    return k == f[k] ? k : f[k] = get(f[k]);
}

static int POS;

static int n;

static int was[N];

static void dfs(int node,int prev,set < int > nodes,set < pii > degs) {
    if (node == POS) {
    	POS = -1;
    	for (auto it : nodes)
    		was[it] = 1;
    }
    for (auto it : g[node])
        if (it != prev) {
            if (nodes.count(it))
                dfs(it,node,nodes,degs);
            else {
                set < int > new_nodes;
                set < pii > new_degs;
                for (auto w : nodes)
                    new_nodes.insert(w);
                int u,v;
                auto low = degs.begin();
                if (low->se == node) 
                    ++low;
                u = low->se;
                for (auto w : nodes)
                    if (G[u].count(w)) {
                        v = w;
                        break;
                    }
                new_nodes.erase(u);
                new_nodes.insert(it);
                color[it] = color[u];
                --deg[u];
                --deg[v];
                ++deg[node];
                ++deg[it];
                for (auto it : new_nodes)
                    new_degs.insert(mp(deg[it],it));
                dfs(it,node,new_nodes,new_degs);
                ++deg[u];
                ++deg[v];
                --deg[node];
                --deg[it];
            }
        }
}

static ll answer = 0;

vi e;

static void DFS(int node,int prev) {
	if (prev != -1) {
		e.pb(node);
	}
	for (auto it : g[node])
		if (it != prev && was[it]) {
			DFS(it,node);
			e.pb(node);
		}
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    n = N;
    for (int i = 0;i < n;++i)
  		f[i] = i,color[i] = -1;
  	for (int i = 0;i < M;++i) {
  		if (get(A[i]) == get(B[i]))
  			continue;
  		g[A[i]].pb(B[i]);
  		g[B[i]].pb(A[i]);
  	    G[A[i]].insert(B[i]);
        G[B[i]].insert(A[i]);
    	f[get(A[i])] = get(B[i]);
  	}
    set < int > nodes;
    set < pii > degs;
    queue < int > Q;
    int TT = -1;
    Q.push(0);
    while (!Q.empty()) {
        int node = Q.front();
        Q.pop();
        nodes.insert(node);
        color[node] = ++TT;
        if (nodes.size() == C)
            break;
        for (auto it : g[node])
            if (!nodes.count(it)) {
                Q.push(it);
            }
    }
    POS = P;
    for (auto u : nodes)
        for (auto v : g[u])
            if (nodes.count(v) && u < v)
                ++deg[u],++deg[v];
    for (auto it : nodes)
        degs.insert(mp(deg[it],it));
    dfs(0,-1,nodes,degs);
    assert(POS == -1);
    assert(accumulate(was,was + N,0) == C);
    POS = P;
    DFS(P,-1);
    answer |= (1ll << color[P]) * V;
    assert(G[P].count(e[0]));
    for (int i = 0;i + 1 < e.size();++i)
    	assert(G[e[i]].count(e[i + 1]));
    for (auto it : e)
    	answer |= (1ll << color[it]) * Move(it);
    return answer;
}

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from Joi.cpp:2:
Joi.cpp: In function 'void connect(std::set<int>)':
Joi.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     assert(cnt + 1 == st.size());
            ~~~~~~~~^~~~~~~~~~~~

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:144:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0;i + 1 < e.size();++i)
                    ~~~~~~^~~~~~~~~~
Ioi.cpp: In function 'void dfs(int, int, std::set<int>, std::set<std::pair<int, int> >)':
Ioi.cpp:78:17: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 ++deg[v];
                 ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2404 KB Output is correct
2 Correct 20 ms 2720 KB Output is correct
3 Correct 34 ms 3352 KB Output is correct
4 Correct 17 ms 4048 KB Output is correct
5 Correct 18 ms 4480 KB Output is correct
6 Correct 28 ms 4480 KB Output is correct
7 Correct 36 ms 5880 KB Output is correct
8 Correct 24 ms 5880 KB Output is correct
9 Correct 29 ms 5880 KB Output is correct
10 Correct 20 ms 5880 KB Output is correct
11 Correct 19 ms 5880 KB Output is correct
12 Correct 12 ms 5880 KB Output is correct
13 Correct 39 ms 5880 KB Output is correct
14 Correct 34 ms 5880 KB Output is correct
15 Correct 36 ms 5880 KB Output is correct
16 Correct 35 ms 5880 KB Output is correct
17 Correct 36 ms 5880 KB Output is correct
18 Correct 35 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1043 ms 10488 KB Output is correct
2 Correct 986 ms 10816 KB Output is correct
3 Correct 979 ms 10816 KB Output is correct
4 Correct 996 ms 10816 KB Output is correct
5 Correct 1203 ms 140480 KB Output is correct
6 Correct 1230 ms 140480 KB Output is correct
7 Correct 1255 ms 140480 KB Output is correct
8 Correct 1164 ms 140480 KB Output is correct
9 Correct 1326 ms 140480 KB Output is correct
10 Correct 856 ms 140480 KB Output is correct
11 Correct 786 ms 140480 KB Output is correct
12 Correct 829 ms 140480 KB Output is correct
13 Correct 857 ms 140480 KB Output is correct
14 Correct 938 ms 140480 KB Output is correct
15 Correct 879 ms 140480 KB Output is correct
16 Correct 843 ms 140480 KB Output is correct
17 Correct 1099 ms 140480 KB Output is correct
18 Correct 1117 ms 140480 KB Output is correct
19 Correct 1010 ms 140480 KB Output is correct
20 Correct 941 ms 155488 KB Output is correct
21 Correct 1156 ms 155488 KB Output is correct
22 Correct 1201 ms 155488 KB Output is correct
23 Correct 1303 ms 155488 KB Output is correct
24 Correct 1074 ms 155488 KB Output is correct
25 Correct 1039 ms 155488 KB Output is correct
26 Correct 1067 ms 155488 KB Output is correct
27 Correct 1213 ms 155488 KB Output is correct
28 Correct 1197 ms 155488 KB Output is correct
29 Correct 954 ms 155488 KB Output is correct
30 Correct 1195 ms 155488 KB Output is correct
31 Correct 20 ms 155488 KB Output is correct
32 Correct 24 ms 155488 KB Output is correct
33 Correct 30 ms 155488 KB Output is correct
34 Correct 22 ms 155488 KB Output is correct
35 Correct 16 ms 155488 KB Output is correct
36 Correct 16 ms 155488 KB Output is correct
37 Correct 15 ms 155488 KB Output is correct
38 Correct 10 ms 155488 KB Output is correct
39 Correct 10 ms 155488 KB Output is correct
40 Correct 15 ms 155488 KB Output is correct
41 Correct 16 ms 155488 KB Output is correct
42 Correct 13 ms 155488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 155488 KB Output is correct
2 Correct 19 ms 155488 KB Output is correct
3 Correct 18 ms 155488 KB Output is correct
4 Correct 214 ms 155488 KB Output is correct
5 Correct 232 ms 155488 KB Output is correct
6 Correct 235 ms 155488 KB Output is correct
7 Correct 221 ms 155488 KB Output is correct
8 Correct 243 ms 155488 KB Output is correct
9 Runtime error 1455 ms 299048 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 991 ms 299048 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1133 ms 299048 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -