답안 #989351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989351 2024-05-28T03:47:52 Z GrindMachine 항공 노선도 (JOI18_airline) C++17
0 / 100
289 ms 16200 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

/*

read some comments about the solution long back, dont really remember much from there (except that we had to somehow encode the bits of each node)

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Alicelib.h"

void Alice( int n, int m, int A[], int B[] ){
	// InitG( 4, 3 );
	// MakeG( 0, 1, 2 );
	// MakeG( 1, 1, 3 );
	// MakeG( 2, 2, 3 );

    if(n == 1){
        InitG(1,0);
        return;
    }

    if(n == 2){
        InitG(2,m);
        if(m){
            MakeG(0,A[0],B[0]);
        }
        return;
    }

    vector<pii> edges;
    vector<int> deg(n+15);

    auto add_edge = [&](int u, int v){
        edges.pb({u,v});
        deg[u]++, deg[v]++;
    };

    rep(i,m){
        add_edge(A[i],B[i]);
    }

    rep(i,n){
        rep(bit,10){
            if((i+1)&(1<<bit)){
                add_edge(i,n+bit);
            }
        }
    }

    rep(i,n){
        add_edge(i,n+10);
    }

    add_edge(n+10,n+11);
    add_edge(n+11,n);
    rep(bit,9){
        add_edge(n+bit,n+bit+1);
    }

    rep(i,n){
        if(deg[i] == n+1){
            add_edge(i,n+12);
        }
        else if(deg[i] == 2){
            add_edge(i,n+12);
        }
    }

    assert(count(all(deg),n+1) == 1);

    InitG(n+13,sz(edges));

    rep(i,n+13){
        cout << deg[i] << " ";
    }
    cout << endl;

    rep(i,sz(edges)){
        MakeG(i,edges[i].ff,edges[i].ss);
    }
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

/*

read some comments about the solution long back, dont really remember much from there (except that we had to somehow encode the bits of each node)

*/

const int MOD = 1e9 + 7;
const int N = 2e3 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Boblib.h"

vector<int> adj[N];

void Bob( int n, int m, int C[], int D[] ){
	// InitMap( 4, 3 );
	// MakeMap( 0, 1 );
	// MakeMap( 0, 2 );
	// MakeMap( 0, 3 );

	if(n == 1){
		InitMap(1,0);
		return;
	}

	if(n == 2){
		InitMap(2,m);
		if(m){
			MakeMap(0,1);
		}
		return;
	}

	int on = n-13;

	vector<int> deg(n);
	rep(i,m){
		int u = C[i], v = D[i];
		deg[u]++, deg[v]++;
		adj[u].pb(v), adj[v].pb(u);
	}

	bool found = false;
	vector<bool> bad(n);
	vector<int> bits;

	rep(i,n){
		if(deg[i] == on+1){
			assert(!found);
			found = true;
			bad[i] = 1;
			int curr = -1;

			trav(j,adj[i]){
				if(deg[j] != 2){
					bad[j] = 1;
				}
				else{
					assert(curr == -1);
					curr = j;
				}
			}

			while(true){
				bits.pb(curr);
				int nxt = -1;
				trav(j,adj[curr]){
					if(bad[j]) conts;
					assert(nxt == -1);
					nxt = j;
				}

				if(nxt == -1) break;
				bad[curr] = 1;
				curr = nxt;
			}
		}
	}

	vector<bool> is_bit(n);
	trav(i,bits) is_bit[i] = 1;
	bits.erase(bits.begin());
	assert(sz(bits) == 10);

	// trav(i,bits){
	// 	cout << deg[i] << endl;
	// }

	vector<int> id(n);

	rep(i,sz(bits)){
		int u = bits[i];
		trav(v,adj[u]){
			if(is_bit[v]) conts;
			id[v] |= (1<<i);
		}
	}

	vector<pii> edges;

	rep(i,m){
		int u = C[i], v = D[i];
		if(id[u] and id[v]){
			edges.pb({id[u],id[v]});
		}
	}	

	InitMap(on,sz(edges));
	for(auto [u,v] : edges){
		u--, v--;
		MakeMap(u,v);
	}
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3416 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3416 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 289 ms 16200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -