제출 #643244

#제출 시각아이디문제언어결과실행 시간메모리
643244ghostwriterBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1465 ms261560 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    VOI23 gold medal
*/
const int oo = 1e9;
const int N = 1e5 + 5;
const int D = 320;
int n, m, q, d[N], c[N], c1[N];
vpi best[N];
vi adj[N];
void merge(vpi &a, vpi &b) {
	vpi ans(2 * D); ans.clear();
	int l = 0;
	EACH(i, a) {
		WHILE(l < sz(b) && b[l].nd > i.nd) ans.pb(b[l++]);
		ans.pb(i);
	}
	WHILE(l < sz(b)) ans.pb(b[l++]);
	vpi ans1(2 * D); ans1.clear();
	EACH(i, ans) {
		if (c1[i.st]) continue;
		ans1.pb(i);
		c1[i.st] = 1;
		if (sz(ans1) == D) break;
	}
	EACH(i, ans) c1[i.st] = 0;
	a = ans1;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> m >> q;
    FOR(i, 1, m) {
    	int s, e;
    	cin >> s >> e;
    	adj[e].pb(s);
    }
    FOR(i, 1, n) {
    	best[i].pb({i, 0});
    	EACH(j, adj[i]) {
    		vpi cur = best[j];
    		EACH(z, cur) ++z.nd;
    		merge(best[i], cur);
    	}
    }
    WHILE(q--) {
    	int t, y;
    	cin >> t >> y;
    	vi C(y, 0);
    	FOR(i, 0, y - 1) {
    		cin >> C[i];
    		c[C[i]] = 1;
    	}
    	if (y >= D) {
    		FOR(i, 1, n) {
    			if (!c[i]) d[i] = 0;
    			else d[i] = -oo;
    			EACH(j, adj[i]) d[i] = max(d[i], d[j] + 1);
    		}
    		cout << max(d[t], -1) << '\n';
    		EACH(i, C) c[i] = 0;
    		continue;
    	}
    	int rs = -1;
    	EACH(j, best[t]) {
    		if (c[j.st]) continue;
    		rs = j.nd;
    		break;
    	}
    	cout << rs << '\n';
		EACH(i, C) c[i] = 0;
    }
    return 0;
}
/*
5 6 3
1 2
2 4
3 4
1 3
3 5
4 5
4 1 1
5 2 2 3
2 3 1 4 5
*/
/*
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
*/

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'void merge(vpi&, vpi&)':
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:50:2: note: in expansion of macro 'EACH'
   50 |  EACH(i, a) {
      |  ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:56:2: note: in expansion of macro 'EACH'
   56 |  EACH(i, ans) {
      |  ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:62:2: note: in expansion of macro 'EACH'
   62 |  EACH(i, ans) c1[i.st] = 0;
      |  ^~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bitaro.cpp:70:5: note: in expansion of macro 'FOR'
   70 |     FOR(i, 1, m) {
      |     ^~~
bitaro.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bitaro.cpp:75:5: note: in expansion of macro 'FOR'
   75 |     FOR(i, 1, n) {
      |     ^~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:77:6: note: in expansion of macro 'EACH'
   77 |      EACH(j, adj[i]) {
      |      ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:79:7: note: in expansion of macro 'EACH'
   79 |       EACH(z, cur) ++z.nd;
      |       ^~~~
bitaro.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bitaro.cpp:87:6: note: in expansion of macro 'FOR'
   87 |      FOR(i, 0, y - 1) {
      |      ^~~
bitaro.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bitaro.cpp:92:7: note: in expansion of macro 'FOR'
   92 |       FOR(i, 1, n) {
      |       ^~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:95:8: note: in expansion of macro 'EACH'
   95 |        EACH(j, adj[i]) d[i] = max(d[i], d[j] + 1);
      |        ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:98:7: note: in expansion of macro 'EACH'
   98 |       EACH(i, C) c[i] = 0;
      |       ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:102:6: note: in expansion of macro 'EACH'
  102 |      EACH(j, best[t]) {
      |      ^~~~
bitaro.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
bitaro.cpp:108:3: note: in expansion of macro 'EACH'
  108 |   EACH(i, C) c[i] = 0;
      |   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...