답안 #587756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587756 2022-07-02T10:21:14 Z cfalas Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 36812 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n;
vi a, b;
vector<vi> adj;
int ans[5500][5500];
int vis[5500][5500];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	cin>>n>>q;
	adj.assign(n+1, vi());
	vector<iii> e(n);
	FOR(i,n){
		cin>>e[i].F.F>>e[i].F.S;
		e[i].S = i+1;
	}
	sort(e.begin(), e.end());
	int pr=-1;
	int ss=0;
	FOR(i,n){
		if(e[i].F.F!=pr){
			ss = i;
		}
		pr = e[i].F.F;
		FORi(j,ss,n){
			if(i==j) continue;
			if(e[j].F.F<=e[i].F.S && e[i].F.S<=e[j].F.S){
				adj[e[i].S].push_back(e[j].S);
			}
			if(e[j].F.F > e[i].F.S) break;
		}
		/*
		cout<<i+1<<": ";
		FOA(v, adj[i+1]) cout<<v<<" ";
		cout<<endl;
		*/
	}
	FORi(i,1,n+1){
		queue<ii> q;
		q.push({0, i});
		FOR(j,n+1) ans[i][j] = MOD, vis[i][j] = 0;
		ans[i][i] = 0;
		vis[i][i] = true;
		while(!q.empty()){
			ii t = q.front();
			q.pop();

			FOA(v, adj[t.S]){
				if(!vis[i][v]){
					ans[i][v] = 1 - t.F;
					vis[i][v] = true;
					q.push({-ans[i][v], v});
				}
			}

		}
	}
	while(q--){
		int a, b;
		cin>>a>>b;
		if(ans[a][b] < MOD) cout<<ans[a][b]<<"\n";
		else cout<<"impossible\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1549 ms 36300 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 21 ms 16212 KB Output is correct
4 Correct 14 ms 16236 KB Output is correct
5 Correct 19 ms 16408 KB Output is correct
6 Incorrect 10 ms 16384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 21 ms 16212 KB Output is correct
4 Correct 14 ms 16236 KB Output is correct
5 Correct 19 ms 16408 KB Output is correct
6 Incorrect 10 ms 16384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 21 ms 16212 KB Output is correct
4 Correct 14 ms 16236 KB Output is correct
5 Correct 19 ms 16408 KB Output is correct
6 Incorrect 10 ms 16384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1545 ms 36812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1549 ms 36300 KB Time limit exceeded
3 Halted 0 ms 0 KB -