답안 #164610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164610 2019-11-22T05:41:28 Z ryansee Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
2000 ms 257460 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll /*long long*/ int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (100006)
#define MAXE (200006)
const ll sqr=305;
ll n,m,q;
int dp[MAXN];
vector<int> v[MAXN];
bitset<MAXN> vis;
vector<int> topo, Q1, Q2, dest;
vector<vector<int>> busy;
vector<ll> ans;
void dfs(int x) {
	if(vis[x]) return;
	vis[x]=1;
	for(auto i:v[x]) dfs(i);
	topo.pb(x);
}
void solve2(){
	vector<vector<pair<int,int>>> dp; vector<pair<int,int>> mx_val(n+1, {-INF, 0}); int co = 1;
	dp.resize(n+1, vector<pair<int,int>>(sqr, {-INF,-1}));
	FOR(i,1,n) dp[i][0]={0, i};
	for(auto i:topo) {
		for(auto j:v[i]) {
			if(dp[i][0].f+1 <= dp[j].back().f) continue;
			vector<pair<int,int>> vals;
			vector<int> ind, ign1, ign2;
			FOR(i,0,sqr-1) if(dp[j][i].s!=-1) ind.pb(dp[j][i].s), mx_val[dp[j][i].s] = {dp[j][i].f, co}; else break;
			ign1.resize(ind.size(), 1);
			ign2.resize(dp[i].size(), 1);
			FOR(j,0,sqr-1) if(dp[i][j].s!=-1) { 
				if(mx_val[dp[i][j].s].s != co);// vals.eb(dp[i][j].f+1, dp[i][j].s); 
				else if(mx_val[dp[i][j].s].f>=dp[i][j].f+1) ign2[j]=0; 
				else mx_val[dp[i][j].s].f=dp[i][j].f+1;
			} else break;
			FOR(i,0,siz(ind)-1) if(mx_val[ind[i]].f != dp[j][i].f) ign1[i]=0;
			ll co1=0, co2=0;
			while(co1<ind.size() || co2<dp[i].size()) {
				if(co1 < ind.size() && ign1[co1]==0) { ++ co1; continue; }
				if(dp[i][co2].s == -1) { co2=dp[i].size(); continue; }
				if(co2 < dp[i].size() && ign2[co2] == 0) { ++ co2; continue; }
				if(co1==ind.size()) vals.eb(dp[i][co2].f+1, dp[i][co2].s), ++co2;
				else if(co2==dp[i].size()) assert(ind[co1]==dp[j][co1].s), vals.eb(dp[j][co1].f, dp[j][co1].s), ++ co1;
				else if(dp[j][co1].f >= dp[i][co2].f+1) assert(ind[co1]==dp[j][co1].s), vals.eb(dp[j][co1].f, dp[j][co1].s), ++co1;
				else vals.eb(dp[i][co2].f+1, dp[i][co2].s), ++co2;
			}
			FOR(i,0,sqr-1) if(vals.size()<=i) dp[j][i]={-INF, -1}; else dp[j][i]=vals[i];
			++ co;
		}
	}
	vis.set();
	for(auto i:Q2) {
		for(auto j:busy[i]) vis[j]=0;
		for(auto j:dp[dest[i]]) if(j.s != -1 && vis[j.s]) {
			ans[i]=j.f; break;
		}
		for(auto j:busy[i]) vis[j]=1;
	}
}
#define gc getchar_unlocked
void in(ll &x) {
	x=0;
	char ch=gc();
	while(ch<'0'||ch>'9') ch=gc();
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+ch-48;
		ch=gc();
	}
}
int main()
{
	FAST
	in(n), in(m), in(q); ans.resize(q, -1);
	FOR(i,0,m-1) {
		ll s, e; in(s),in(e);
		v[s].eb(e);
	}
	FOR(i,0,q-1) {
		busy.pb(vector<int>());
		ll t, y; in(t),in(y); dest.pb(t); busy.back().resize(y, 0);
		FOR(i,0,y-1) in(busy.back()[i]);
		if(y >= sqr) Q1.pb(i); else Q2.pb(i);
	}
	FOR(i,1,n) dfs(i);
	reverse(all(topo));
	vis.set();
	for(auto i:Q1) {
		FOR(i,1,n) dp[i]=-1e9;
		for(auto j:busy[i]) vis[j]=0;
		for(auto i:topo) {
			if(vis[i]) dp[i]=max(dp[i], 0);
			for(auto j:v[i]) {
				dp[j]=max(dp[j], dp[i]+1);
			}
		}
		if(dp[dest[i]] >= 0) ans[i]=dp[dest[i]];
		for(auto j:busy[i]) vis[j]=1;
	}
	solve2();
	FOR(i,0,q-1) {
		cout<<(ans[i]<0?-1:ans[i])<<'\n';
	}
}

Compilation message

bitaro.cpp: In function 'void solve2()':
bitaro.cpp:66:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(co1<ind.size() || co2<dp[i].size()) {
          ~~~^~~~~~~~~~~
bitaro.cpp:66:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(co1<ind.size() || co2<dp[i].size()) {
                            ~~~^~~~~~~~~~~~~
bitaro.cpp:67:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(co1 < ind.size() && ign1[co1]==0) { ++ co1; continue; }
        ~~~~^~~~~~~~~~~~
bitaro.cpp:69:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(co2 < dp[i].size() && ign2[co2] == 0) { ++ co2; continue; }
        ~~~~^~~~~~~~~~~~~~
bitaro.cpp:70:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(co1==ind.size()) vals.eb(dp[i][co2].f+1, dp[i][co2].s), ++co2;
        ~~~^~~~~~~~~~~~
bitaro.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     else if(co2==dp[i].size()) assert(ind[co1]==dp[j][co1].s), vals.eb(dp[j][co1].f, dp[j][co1].s), ++ co1;
             ~~~^~~~~~~~~~~~~~
bitaro.cpp:75:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    FOR(i,0,sqr-1) if(vals.size()<=i) dp[j][i]={-INF, -1}; else dp[j][i]=vals[i];
                      ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 11 ms 5240 KB Output is correct
6 Correct 11 ms 5240 KB Output is correct
7 Correct 12 ms 5240 KB Output is correct
8 Correct 17 ms 5240 KB Output is correct
9 Correct 17 ms 5240 KB Output is correct
10 Correct 18 ms 5240 KB Output is correct
11 Correct 16 ms 5240 KB Output is correct
12 Correct 14 ms 5240 KB Output is correct
13 Correct 16 ms 5240 KB Output is correct
14 Correct 16 ms 5240 KB Output is correct
15 Correct 14 ms 5240 KB Output is correct
16 Correct 15 ms 5240 KB Output is correct
17 Correct 15 ms 5240 KB Output is correct
18 Correct 13 ms 5240 KB Output is correct
19 Correct 16 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 11 ms 5240 KB Output is correct
6 Correct 11 ms 5240 KB Output is correct
7 Correct 12 ms 5240 KB Output is correct
8 Correct 17 ms 5240 KB Output is correct
9 Correct 17 ms 5240 KB Output is correct
10 Correct 18 ms 5240 KB Output is correct
11 Correct 16 ms 5240 KB Output is correct
12 Correct 14 ms 5240 KB Output is correct
13 Correct 16 ms 5240 KB Output is correct
14 Correct 16 ms 5240 KB Output is correct
15 Correct 14 ms 5240 KB Output is correct
16 Correct 15 ms 5240 KB Output is correct
17 Correct 15 ms 5240 KB Output is correct
18 Correct 13 ms 5240 KB Output is correct
19 Correct 16 ms 5244 KB Output is correct
20 Correct 1211 ms 7996 KB Output is correct
21 Correct 1166 ms 8072 KB Output is correct
22 Correct 1177 ms 7864 KB Output is correct
23 Correct 1365 ms 7928 KB Output is correct
24 Correct 1453 ms 251360 KB Output is correct
25 Correct 1522 ms 251348 KB Output is correct
26 Correct 1495 ms 251380 KB Output is correct
27 Correct 1691 ms 257124 KB Output is correct
28 Correct 1728 ms 257132 KB Output is correct
29 Correct 1703 ms 257128 KB Output is correct
30 Correct 1678 ms 251768 KB Output is correct
31 Correct 1796 ms 251732 KB Output is correct
32 Correct 1664 ms 251760 KB Output is correct
33 Correct 1370 ms 253268 KB Output is correct
34 Correct 1400 ms 252520 KB Output is correct
35 Correct 1367 ms 253040 KB Output is correct
36 Correct 1617 ms 253300 KB Output is correct
37 Correct 1609 ms 252276 KB Output is correct
38 Correct 1569 ms 253304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 11 ms 5240 KB Output is correct
6 Correct 11 ms 5240 KB Output is correct
7 Correct 12 ms 5240 KB Output is correct
8 Correct 17 ms 5240 KB Output is correct
9 Correct 17 ms 5240 KB Output is correct
10 Correct 18 ms 5240 KB Output is correct
11 Correct 16 ms 5240 KB Output is correct
12 Correct 14 ms 5240 KB Output is correct
13 Correct 16 ms 5240 KB Output is correct
14 Correct 16 ms 5240 KB Output is correct
15 Correct 14 ms 5240 KB Output is correct
16 Correct 15 ms 5240 KB Output is correct
17 Correct 15 ms 5240 KB Output is correct
18 Correct 13 ms 5240 KB Output is correct
19 Correct 16 ms 5244 KB Output is correct
20 Correct 1211 ms 7996 KB Output is correct
21 Correct 1166 ms 8072 KB Output is correct
22 Correct 1177 ms 7864 KB Output is correct
23 Correct 1365 ms 7928 KB Output is correct
24 Correct 1453 ms 251360 KB Output is correct
25 Correct 1522 ms 251348 KB Output is correct
26 Correct 1495 ms 251380 KB Output is correct
27 Correct 1691 ms 257124 KB Output is correct
28 Correct 1728 ms 257132 KB Output is correct
29 Correct 1703 ms 257128 KB Output is correct
30 Correct 1678 ms 251768 KB Output is correct
31 Correct 1796 ms 251732 KB Output is correct
32 Correct 1664 ms 251760 KB Output is correct
33 Correct 1370 ms 253268 KB Output is correct
34 Correct 1400 ms 252520 KB Output is correct
35 Correct 1367 ms 253040 KB Output is correct
36 Correct 1617 ms 253300 KB Output is correct
37 Correct 1609 ms 252276 KB Output is correct
38 Correct 1569 ms 253304 KB Output is correct
39 Correct 1519 ms 257460 KB Output is correct
40 Correct 1481 ms 252032 KB Output is correct
41 Correct 1428 ms 251636 KB Output is correct
42 Execution timed out 2078 ms 251820 KB Time limit exceeded
43 Halted 0 ms 0 KB -